Game Development Community

Script function from source

by Chris Labombard · in Torque Game Engine · 10/14/2005 (9:29 am) · 7 replies

I'm trying to execute a script function from source.

Im using this:
F32 points = 1.05;
Con::executef(2,"addPoints",points);

To call this:

function addPoints(%points)
{
	$totalPoints += %points;
}

It's giving me an error and crashing the app.

I've also tried it with tihs:

Con::executef(1,"addPoints",points);

It doesnt crash, but doesnt add points.


I'm pretty sure the problem is that the float im sending through needs to be a string.

Is there a function to convert a float to a string ?

About the author

I have been a professional game programmer for over 5 years now. I've worked on virtually every platform, dozens of games and released a few of my own games, including 2 iPhone titles and a title waiting release on Big Fish Games.


#1
10/14/2005 (9:33 am)
I ran into this the other day. This should do the trick:

Con::getFloatArg( points );
#2
10/14/2005 (9:51 am)
Owen - points is defined in my c++ code. I need to add it to $totalPoints in script.

I don't see how to do that with the code you provided.

Thank you for your reply.
#3
10/14/2005 (9:54 am)
Nevermind. I was having a blonde moment. You meant this:

Con::executef(2,"addPoints",Con::getFloatArg( points ));
#4
10/14/2005 (9:56 am)
Yep.

I think you could also use dSprintf() for this, but getFloatArg() was designed specifically for generating arguments for script function calls.
#5
10/14/2005 (9:57 am)
Owen - I got you... You have a faulty argument in your statmeent though... Should be a 2, not a 1.
#6
10/14/2005 (10:00 am)
Thanks for your help. Much appreciated. :)
#7
10/14/2005 (11:27 am)
Just to reinforce: any parameter sent between script and engine (in either direction) must be a string. Common uses:

Script to Engine via ConsoleMethod() : already done for you on the script side (everything is a string anyway), but you must implement some form of string parsing in the ConsolMethod implementation itself. dSscanf is a common tactic. Note that the arguments that become interesting to the ConsoleMethod itself start with argc = 2 (argv[2]). argv[0] is the class of the calling object, and argv[1] is the function name.

Engine to Script via Con::executef() : common techniques are using Con::getReturnBuffer() to grab some string space, and then dSprintf() to put the data into a space delimited format. There are alternative techniques as well (see above).