This project has moved and is read-only. For the latest updates, please go here.

Need a little help on making functions

Nov 21, 2011 at 7:09 PM

I can't seem to find out myself, but i want to do the folliwing (in a script)

var x = returnfunction()

returnfunction is a stupidname but its obvious that its a custom function. So how do i do this on the C# side? :)


Thanks in advance ^^

Nov 21, 2011 at 8:38 PM
Edited Nov 21, 2011 at 8:39 PM

Use either:

engine.SetGlobalValue("x", returnfunction());


engine.SetGlobalValue("x", engine.Evaluate("returnfunction()"));

 Depending on whether returnfunction is a javascript function or a c# function.

Nov 21, 2011 at 10:30 PM

I think you misunderstood me :)

I will put it a bit more into context. I am making a roguelike game and want it to be scriptable, i chosen Jurassic for it :p
Now i want to be able to create a entity from script (entity contains the graphic and the XY coords)

What i want, is kinda this (in javascript)

var ent1 = new Entity(1, 1, "#");

So this would create a new entity at position 1, 1 with a graphic of # (it's textbased :p)

The thing i'm looking for is that i now can do things like this (also in javascript)

ent1.X = 5;
ent1.Y = 3;
ent1.Icon = "@";
So basicly what i want is that i make a new instance of a class or use a function with a return value in javascript

Nov 21, 2011 at 11:55 PM

Hmm, I'm still not entirely sure what you need, but have you looked at this page?

This explains how to create a class in .NET and then create instances of it in javascript.

Nov 22, 2011 at 9:13 AM

I have found out how to for functions (delegates have a output part, silly me)

And there was indeed documentation on how to make a instanced class, but i must have missed it or slipped my mind (again, silly me xD)

Thanks for the help :D