C# or Python?

06/04/2013 00:31 Eteru#1
So, I have been using pro4never's Albetros source lately to learn some stuff, and I have been wondering...

Are there, if any benefits to using Python over C# for NPCs or anything else?

I have found that Python can be quite annoying-- I constantly am having to go over ALL of the code to make sure there are not any "tabs" instead of spaces and other things as well. I also was thinking that since you have to write in code to use Python in the source that it would just be easier to use C#. I have been using Notepad++ with "Python" as the language as well as replacing "tab" with 4 spaces as Python requires, but I feel like using MSVS 2010U is better than trying to mess with Python. Yes, I understand that I can change the scripts for NPCs with Python without having to restart the server, but could this also be changed somehow for the C# code...?

Any thoughts, comments?
06/04/2013 00:45 pro4never#2
We used external scripts because

A: Developers could code npcs without having access to our source. Useful when you maybe have some less experienced people on your development team.

B: Scripts are loaded as the npc is clicked. As such it updates instantly ingame when testing and developing new features.


If you want to develop using python scripts then you should use a python editor. That will solve your tab issues.
06/04/2013 01:29 Eteru#3
Quote:
Originally Posted by pro4never View Post
We used external scripts because

A: Developers could code npcs without having access to our source. Useful when you maybe have some less experienced people on your development team.

B: Scripts are loaded as the npc is clicked. As such it updates instantly ingame when testing and developing new features.


If you want to develop using python scripts then you should use a python editor. That will solve your tab issues.
That's good reason. As I've only myself working on the server, I didn't really consider that reason (A).

Yeah, I know the loading as clicked, I was just wondering if maybe there were other reasons like, efficiency of the code (minus loading on click) or anything.

Also, since you replied here, I was having some issues with a couple of the scripts like eh.. "AddItems" and "RemoveItems." I since have just used C# because I didn't understand what the issue was seeing as how the others seemed to work. If I come across the error again, I'll make sure to screenshot it. I believe it was something like "AddItems" didn't exist or something, but I can see it perfectly in the C# Npc.cs code. o.O
06/04/2013 03:10 Super Aids#4
You can also do a script engine using C#, that is what I'm using for tournaments, events, npcs and items xD

Personally I'd say use C# if your source is C#, because keeping it all to the same language will simplify things.
06/04/2013 03:48 Eteru#5
Quote:
Originally Posted by Super Aids View Post
You can also do a script engine using C#, that is what I'm using for tournaments, events, npcs and items xD

Personally I'd say use C# if your source is C#, because keeping it all to the same language will simplify things.
Yeah? So you can do exactly what I do with Python as external script, but with C#? I'm sure I'd have to figure out myself how to do that... >_< Changing it from Python to C# external, that is. Would you have to add in stuff like the Python one has in NPC.cs like eh.. "AddItem" "Text("texthere)"? Or could I type just as I do in the .cs files o_O
06/04/2013 05:26 Super Aids#6
You can call everything in your source. System.Reflection is your friend.

Here is the old version of mine, it may not be suitable unless you modify it.
[Only registered and activated users can see links. Click Here To Register...]

In case you want an example:
Code:
public static void script_702(GameClient client, byte option) // script_ before the id is necessary!
{
	switch (option)
	{
		case 0:
			{
				if (client.SpouseDatabaseUID == 0)
				{
					NPCHandler.SendDialog(client, "Is there someone you love and wants to marry?");
					NPCHandler.SendOption(client, "I've found the love of my life.", 1);
				}
				else
				{
					NPCHandler.SendDialog(client, "Perhaps you're unhappy in your marriage?");
					NPCHandler.SendOption(client, "I want to get divorced.", 1);					
				}
				NPCHandler.SendOption(client, "No thanks.", 255);
				NPCHandler.Finish(client);
				break;
			}
		case 1:
			{
				if (client.SpouseDatabaseUID == 0)
					NPCHandler.Marriage(client);
				else
					NPCHandler.Divorce(client);
				break;
			}
	}
}
06/04/2013 06:30 pro4never#7
Yup you can use any language you wish. I believe it was bio hazard who was working on all the scripting in albetros so I just let him do whatever he wanted. He decided on iron python so I just went along with it and added a few methods for him to use when coding npcs.
06/04/2013 06:36 Eteru#8
Quote:
Originally Posted by Super Aids View Post
You can call everything in your source. System.Reflection is your friend.

Here is the old version of mine, it may not be suitable unless you modify it.
[Only registered and activated users can see links. Click Here To Register...]

In case you want an example:
Code:
public static void script_702(GameClient client, byte option) // script_ before the id is necessary!
{
	switch (option)
	{
		case 0:
			{
				if (client.SpouseDatabaseUID == 0)
				{
					NPCHandler.SendDialog(client, "Is there someone you love and wants to marry?");
					NPCHandler.SendOption(client, "I've found the love of my life.", 1);
				}
				else
				{
					NPCHandler.SendDialog(client, "Perhaps you're unhappy in your marriage?");
					NPCHandler.SendOption(client, "I want to get divorced.", 1);					
				}
				NPCHandler.SendOption(client, "No thanks.", 255);
				NPCHandler.Finish(client);
				break;
			}
		case 1:
			{
				if (client.SpouseDatabaseUID == 0)
					NPCHandler.Marriage(client);
				else
					NPCHandler.Divorce(client);
				break;
			}
	}
}
Thanks! Nice to see an example, too.

Quote:
Originally Posted by pro4never View Post
Yup you can use any language you wish. I believe it was bio hazard who was working on all the scripting in albetros so I just let him do whatever he wanted. He decided on iron python so I just went along with it and added a few methods for him to use when coding npcs.
Well, that's good to know. I think Python is probably an "easier" language, but if I can still use VS to edit the NPCs externally, I think it will give me more control over what I want to do, and also be able to catch little errors I might have.

Thanks, to you both. I will try to do this.
06/04/2013 15:22 CptSky#9
I did my own "scripting language" based on INI syntax to let people with NO coding knowledge do NPCs. You had only to understand the requirements & rewards field and that if you added several blocks to the page, it was like a if/elseif/else.

Today, I would go for Lua, because C# reflection must be used in C#, while Lua can be used in any language.
06/04/2013 20:24 InfamousNoone#10
I still heavily prefer Python over Lua
06/04/2013 20:34 pro4never#11
Quote:
Originally Posted by InfamousNoone View Post
I still heavily prefer Python over Lua
Amen.

I've done a little bit of scripting in LUA for various bots before and as much as python can tick me off some times, I'd definitely prefer it.
06/04/2013 21:27 CptSky#12
Quote:
Originally Posted by InfamousNoone View Post
I still heavily prefer Python over Lua
Quote:
Originally Posted by pro4never View Post
Amen.

I've done a little bit of scripting in LUA for various bots before and as much as python can tick me off some times, I'd definitely prefer it.
Lua, although really limited due to the goal of always doing something really small, portable and fast, is fine. I've never used Python. I'm sure it has more features than Lua (not really hard to beat). It just that NPC scripting was always relayed to second plan when I worked on server projects. So, I would still go for something I already know how to implement easily :p
06/05/2013 02:15 Ultimation#13
Personally if someone took some time and did a nice IDE for Lua (no good ones to my knowledge but am happy to be proven wrong). Lua would be the best option because of its flexability. (IMO)

The downside with Lua is like with any scripting language. is The Syntax can get very untidy and a bit tricky to follow.

But, yea that can be solved to a point.

Id go for Lua over c#.

Lua over Python (i can't judge - never used Python)


Just my 2 cents worth :)
06/05/2013 21:37 Eteru#14
Quote:
Originally Posted by CptSky View Post
I did my own "scripting language" based on INI syntax to let people with NO coding knowledge do NPCs. You had only to understand the requirements & rewards field and that if you added several blocks to the page, it was like a if/elseif/else.

Today, I would go for Lua, because C# reflection must be used in C#, while Lua can be used in any language.
Quote:
Originally Posted by Ultimation View Post
Personally if someone took some time and did a nice IDE for Lua (no good ones to my knowledge but am happy to be proven wrong). Lua would be the best option because of its flexability. (IMO)

The downside with Lua is like with any scripting language. is The Syntax can get very untidy and a bit tricky to follow.

But, yea that can be solved to a point.

Id go for Lua over c#.

Lua over Python (i can't judge - never used Python)


Just my 2 cents worth :)
I have never even heard of, Lua, actually. Any example as to how it's actually used? Also, in regards to using INI files, I read someone say on the forums that it can take a lot of RAM to use INI files for a lot of other things? I was mainly looking for something that I can have the system check for me for stupid little mistakes like spacing, or maybe I didn't add a punctuation mark ie: ,";: etc. and for efficiency.

And I also thought maybe using C# would give me more "use" or function, I guess to say.
06/05/2013 22:25 pro4never#15
Quote:
Originally Posted by Eteru View Post
I have never even heard of, Lua, actually. Any example as to how it's actually used? Also, in regards to using INI files, I read someone say on the forums that it can take a lot of RAM to use INI files for a lot of other things? I was mainly looking for something that I can have the system check for me for stupid little mistakes like spacing, or maybe I didn't add a punctuation mark ie: ,";: etc. and for efficiency.

And I also thought maybe using C# would give me more "use" or function, I guess to say.

LUA is a scripting language. It's incredibly popular across many programs and my main experience with it would be commercial bots for large games such as guild wars 2, league of legends, etc.


INI files are just a way of structuring text documents so that they can be parsed easier. If you're writing INI 'scripts' you're really just writing your own little scripting language from scratch using a format that makes it easier to parse. INI is comparable to an XML document as far as purpose is concerned. Either would work very well for simple things like NPCS but it has no real 'logic' in and of itself, that's why you'd be better off using a scripting language if you were trying to write something more complex... such as monster AI using external scripts (lua would be ideal there)


The complaints about INI files and ram would be people loading the same document into memory and never disposing of it after. Therefor every time you use an NPC it would load another copy into memory. As such they start to feel that INI uses up a lot of ram when really it's just them mishandling it.


PS: LUA is quite simple to use. It's a pain to debug (in my opinion) but the actual syntax is easy. Any time I've used it I just use notepad++ for editing it. Works great for me.


Here's some example LUA from a script I wrote for the league of legends bot I mentioned to give you a taste (note, may be messy I suck with lua)

Code:
--[[Clear all elements created by ownerID (aka script ID)]]--
function RemoveObjectsByID(ownerID)
	for x=#Windows,1,-1 do
		for y=#Windows[x].children,1,-1 do
			if Windows[x].children[y].ownerID == ownerID then
				printtext("Removing child with Key: "..Windows[x].children[y].key.."\n")
				table.remove(Windows[x].children, y)
			end
		end
		if Windows[x].ownerID == ownerID then
			printtext("Removing window with title: "..Windows[x].title.."\n")
			table.remove(Windows, x)
		end
	end
end

function GetMouseState()
	return {x=GetCursorX(), y=GetCursorY()}
end

function WindowContainsMouse(window,mouse)
	return window.x < mouse.x 
	and window.x+window.width > mouse.x 
	and window.y < mouse.y 
	and window.y + 20 + #window.children*VerticalSpacing > mouse.y
end


function GetChildElementClicked(window,mouse)
	return window.children[1+math.floor((mouse.y-window.y-20)/VerticalSpacing)]
end