Advertisement

AngelScript 2.5.0c released

Started by January 15, 2006 07:41 PM
44 comments, last by WitchLord 19 years ago
i am trying to pass a float variable to the script, but it never works.

any help is appreciated.


//--------------------- Angel Script ------------------------
void Draw (float& in ticks_passed)
OR
void Draw (float ticks_passed)


//--------------------- C++ ------------------------

float move_count;

ScriptEngine_SetArguments(Context, "p", &move_count);
OR
ScriptEngine_SetArguments(Context, "f", move_count);


this is how i passed the parameters:

void ScriptEngine_SetArguments(asIScriptContext *ctx, char *args, ... )
{
va_list marker;
unsigned long stackPos = 0;
unsigned int variableCount;

va_start( marker, args );

for (variableCount = 0 ; variableCount < strlen(args) ; variableCount++)
{
unsigned long i;
float f;
void *p;
double d;

switch (args[variableCount])
{
case 'i':
i = va_arg(marker, unsigned long);
ctx->SetArgDWord(stackPos, i);
break;

case 'f':
f = va_arg(marker, float);
ctx->SetArgFloat(stackPos, f);
break;

case 'd':
d = va_arg(marker, double);
ctx->SetArgDouble(stackPos, d);
break;

case 'p':
p = va_arg(marker, void *);
ctx->SetArgObject(stackPos, p);
break;

default:
// should handle unknown argument type here
break;
}

stackPos++;
}

va_end( marker );
}


iram:

How about opening a new thread when you're having a problem? That way it will be easier for me keep track of open questions.

You have an error in your code. When the script takes a reference to a value you should actually pass the pointer to the context with the method SetArgDWord(), not SetArgObject(). This would explain why your program fails with your first alternative.

I cannot see any obvious error with your second alternative that passes the float by value. Have you tried debugging the program in order to figure out where it goes wrong? For example: what's the value of move_count passed to ScriptEngine_SetArguments() and what's the value of the float that va_arg() extracts from the arguments? What's the return code for SetArgFloat()?

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
sorry, will use new thread for new question. :P

2 fixes:
a) add a new code to handle passing a reference to a value, then pass using SetArgDWord()

b) when passing a float value, it must be va_arg as double first and cast back to float. no value available if you take it as float

it is working now, thanks a lot.

I suspected it was something like that. I had always wondered how printf() could differentiate between float and double, when the symbol used is the same. This explains it. [smile]

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

It's been difficult to find the time to work on AngelScript these past weeks. Not much has been done on the upcoming version since the last WIP. Hopefully this should change soon, as I'm eager to get back to improving the library for you again.

In the meantime, I've been able to add a couple of bug fixes to the 2.5.0 version.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement