Scripting via IronPython

04/23/2014 19:59 InsomniacPro#1
So now, I'm pretty sure, approx 99.2% affirmative that I have ironpython setup correctly. Now when I utilize this code.
Code:
                    var Test = scope.GetVariable<Func<GameClient, ushort, int>>("npc");
                    Test(Client, option);
                    runtime.Shutdown();
I'll get the error
[Only registered and activated users can see links. Click Here To Register...]

Now, has anyone come across this error?
I'm pretty new to IronPython, so please bear with me.

Thanks for any help.
04/23/2014 21:09 Aceking#2
Can't say I have ever scripted with iron python.

But judging from the error, try:

Code:
    var Test = scope.GetVariable<Func<GameClient, short, int>>("npc");
04/23/2014 22:40 InsomniacPro#3
Quote:
Originally Posted by Aceking View Post
Can't say I have ever scripted with iron python.

But judging from the error, try:

Code:
    var Test = scope.GetVariable<Func<GameClient, short, int>>("npc");
I've tried all data types. No luck.
04/23/2014 22:43 abdoumatrix#4
just stupid question

why u use ironpython for npcscripting?

i would go with a similar script engine like
[Only registered and activated users can see links. Click Here To Register...]
's one.
04/23/2014 22:44 InsomniacPro#5
Quote:
Originally Posted by abdoumatrix View Post
just stupid question

why u use ironpython for npcscripting?

i would go with a similar script engine like
[Only registered and activated users can see links. Click Here To Register...]
's one.
I can ask the same question to the OP of that source as to why he didn't use IronPython.
04/23/2014 23:01 SteveRambo#6
It seems like a bug in your Python script
04/23/2014 23:08 Y u k i#7
Quote:
Originally Posted by abdoumatrix View Post
just stupid question

why u use ironpython for npcscripting?

i would go with a similar script engine like
[Only registered and activated users can see links. Click Here To Register...]
's one.
Probably because apple pie isn't as tasty as strawberry ice.

[Only registered and activated users can see links. Click Here To Register...]
04/23/2014 23:32 -impulse-#8
Quote:
Originally Posted by InsomniacPro View Post
I can ask the same question to the OP of that source as to why he didn't use IronPython.
Why use ProjectX's scripting engine?
1. You can script in C#/VB
2. The scripts are compiled to IL and loaded only once (although, by the looks of it, Super Aids has implemented, but does not use [might use a command or something for that too], something that reloads the scripts)
3. The scope of the script is handled by .net (that is if the script is loaded in the same AppDomain)
4. Once a script is compiled and the method info is kept in a dictionary using it would be like invoking any function using Delegate.Invoke.

Why not to use it as is:
1. Reloading one script would require copying the contents of all the existing scripts into one file, then compile it, to update all preloaded scripts.
2. When you write a script, the method name will have to follow C#'s/VB's guidelines regarding the method name, so you can't use something like script_1-100,200-400(...) to avoid making 299 files for the same function.

Why use IronPython?
1. If you love/want to learn Python, you will obviously want to use IronPython.
2. It's an easy scripting language which provides lots of features

Why not use IronPython?
1. The scope is handled by you by setting variables.
2. Writing scripts with IronPython can be tricky if you want to use .net libraries or w/e without auto completition (although it is possible with Wing [maybe with others too?], as I was just reading).

I don't use Python much so I couldn't find more reason as to why to use or why not to use it. Although if you're interested into performance, using compiled C#/VB scripts is faster.
04/23/2014 23:34 InsomniacPro#9
Quote:
Originally Posted by -impulse- View Post
Why use ProjectX's scripting engine?
1. You can script in C#/VB
2. The scripts are compiled to IL and loaded only once (although, by the looks of it, Super Aids has implemented, but does not use [might use a command or something for that too], something that reloads the scripts)
3. The scope of the script is handled by .net (that is if the script is loaded in the same AppDomain)
4. Once a script is compiled and the method info is kept in a dictionary using it would be like invoking any function using Delegate.Invoke.

Why not to use it as is:
1. Reloading one script would require copying the contents of all the existing scripts into one file, then compile it, to update all preloaded scripts.
2. When you write a script, the method name will have to follow C#'s/VB's guidelines regarding the method name, so you can't use something like script_1-100,200-400(...) to avoid making 299 files for the same function.

Why use IronPython?
1. If you love/want to learn Python, you will obviously want to use IronPython.
2. It's an easy scripting language which provides lots of features

Why not use IronPython?
1. The scope is handled by you by setting variables.
2. Writing scripts with IronPython can be tricky if you want to use .net libraries or w/e without auto completition (although it is possible with Wing [maybe with others too?], as I was just reading).

I don't use Python much so I couldn't find more reason as to why to use or why not to use it. Although if you're interested into performance, using compiled C#/VB scripts is faster.
Well, after reading this, and doing my own personal research ofc, I guess I will go along the lines of what Jacob made and do all that. Keeping C# syntax is a big deal to me, so thanks Alex.
04/24/2014 08:08 Super Aids#10
Quote:
Originally Posted by -impulse- View Post
Why use ProjectX's scripting engine?
1. You can script in C#/VB
2. The scripts are compiled to IL and loaded only once (although, by the looks of it, Super Aids has implemented, but does not use [might use a command or something for that too], something that reloads the scripts)
3. The scope of the script is handled by .net (that is if the script is loaded in the same AppDomain)
4. Once a script is compiled and the method info is kept in a dictionary using it would be like invoking any function using Delegate.Invoke.

Why not to use it as is:
1. Reloading one script would require copying the contents of all the existing scripts into one file, then compile it, to update all preloaded scripts.
2. When you write a script, the method name will have to follow C#'s/VB's guidelines regarding the method name, so you can't use something like script_1-100,200-400(...) to avoid making 299 files for the same function.

Why use IronPython?
1. If you love/want to learn Python, you will obviously want to use IronPython.
2. It's an easy scripting language which provides lots of features

Why not use IronPython?
1. The scope is handled by you by setting variables.
2. Writing scripts with IronPython can be tricky if you want to use .net libraries or w/e without auto completition (although it is possible with Wing [maybe with others too?], as I was just reading).

I don't use Python much so I couldn't find more reason as to why to use or why not to use it. Although if you're interested into performance, using compiled C#/VB scripts is faster.
What I did for the reload was using FileSystemWatcher.

I did some heavy optimization and changes to it when I worked on coding for Insomnius. Since I used it to implement dynamic events so lots of features could be edited/added at runtime like tournaments, commands, playerdebugging, time specific actions etc.

Imma see if I can find it, in case it would be necessary else I might just rewrite the engine from that source.
04/24/2014 12:04 KraHen#11
Quote:
Originally Posted by -impulse- View Post
Why use ProjectX's scripting engine?
I don't use Python much so I couldn't find more reason as to why to use or why not to use it. Although if you're interested into performance, using compiled C#/VB scripts is faster.
Nope. IronPython can be compiled as well, and stored into the memory. It`s not a matter of performance, it`s a matter of preference (and maybe compile speed as well. I personally would suggest to everyone who wants to implement a scripting engine to go with what he/she or the other devs are more confortable with, the minimal performance differences(that is, if you handle everything correctly in the parser/whatever) don`t count as much here as the productivity rate.

On the other side, wb bro, haven`t seem you for some time now. :D
04/24/2014 13:17 -impulse-#12
Quote:
Originally Posted by KraHen View Post
Nope. IronPython can be compiled as well, and stored into the memory. It`s not a matter of performance, it`s a matter of preference (and maybe compile speed as well. I personally would suggest to everyone who wants to implement a scripting engine to go with what he/she or the other devs are more confortable with, the minimal performance differences(that is, if you handle everything correctly in the parser/whatever) don`t count as much here as the productivity rate.

On the other side, wb bro, haven`t seem you for some time now. :D
Uhm, no. Because even if python is compiled, it is still is interpreted 2 times. First from the pyc and then as IL compared to C#/VB where it's only IL.

There's a lot of threads on this topic, one of which is:
[Only registered and activated users can see links. Click Here To Register...]
The opinions vary, but at balance C# > IronPython.

Anyway, I am not sure how debugging would go... With C# I can generate a pdb in memory and have a full stacktrace whenever an exception appears. With IronPython the errors look weird...

I've been around. I am always skulking in the shadows.
04/25/2014 02:01 { Angelius }#13
PHP Code:
using System.CodeDom.Compiler;

public class 
ScriptEngine
{
    private static 
CodeDomProvider Provider CodeDomProvider.CreateProvider("CSharp");
    public static 
CompilerResults Compile(string CodeCompilerParameters Parameters)
    {
        
Parameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
        
Parameters.CompilerOptions "/t:library";
        
Parameters.GenerateInMemory true;
        
CompilerResults cr Provider.CompileAssemblyFromSource(ParametersCode);
        if (
cr.Errors.Count 0)
        {
            
//Error out
            
return null;
        }
        return 
cr;
    }

Ideas ?
04/25/2014 02:46 KraHen#14
Quote:
Originally Posted by -impulse- View Post
Uhm, no. Because even if python is compiled, it is still is interpreted 2 times. First from the pyc and then as IL compared to C#/VB where it's only IL.

There's a lot of threads on this topic, one of which is:
[Only registered and activated users can see links. Click Here To Register...]
The opinions vary, but at balance C# > IronPython.

Anyway, I am not sure how debugging would go... With C# I can generate a pdb in memory and have a full stacktrace whenever an exception appears. With IronPython the errors look weird...

I've been around. I am always skulking in the shadows.
2 times for this amount of scripts is still not a problem, not even with 2k+ players, the same method is used with LUA in commercial games and it works wonders.

Anyhow, debugging is easy, with PTVS it gets really easy (also, you can debug standard python as well).
04/25/2014 13:10 -impulse-#15
Quote:
Originally Posted by { Angelius } View Post
PHP Code:
using System.CodeDom.Compiler;

public class 
ScriptEngine
{
    private static 
CodeDomProvider Provider CodeDomProvider.CreateProvider("CSharp");
    public static 
CompilerResults Compile(string CodeCompilerParameters Parameters)
    {
        
Parameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
        
Parameters.CompilerOptions "/t:library";
        
Parameters.GenerateInMemory true;
        
CompilerResults cr Provider.CompileAssemblyFromSource(ParametersCode);
        if (
cr.Errors.Count 0)
        {
            
//Error out
            
return null;
        }
        return 
cr;
    }

Ideas ?
This is what I use to compile and extract only the method I require from a script:


To be able to compile in parallel you have to use a different object of CompilerParameters (because the compiler parameters generates only one random temp file name, when it's constructed, not when you do the actual compiling).

My scripts look something like:

PHP Code:
using System;
using CoEmuLibrary;
using CoEmuLibrary.Packets;

class 
Main
{
    public static 
unsafe void Execute(Item itemIGameClient client)
    
//public static unsafe void Execute(IntPtr ptr, IGameClient client) // for handling pointers to packets or w/e
    
{
    }