This project has moved. For the latest updates, please go here.

Need a little help on making functions

Nov 21, 2011 at 6: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 ^^

Coordinator
Nov 21, 2011 at 7:38 PM
Edited Nov 21, 2011 at 7:39 PM

Use either:

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

Or:

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

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

Nov 21, 2011 at 9: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

Coordinator
Nov 21, 2011 at 10:55 PM

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

http://jurassic.codeplex.com/wikipage?title=Exposing%20a%20.NET%20class%20to%20JavaScript&referringTitle=Documentation

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

Nov 22, 2011 at 8: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