Setting and Getting a Global Var

Started by
10 comments, last by WitchLord 18 years, 3 months ago
Okay guys, I've been trying to figure out why this isn't working like the docs say it should(unless I've read the docs wrong). All I'm trying to do is set a global property and then retrieve it, and all I get is errors.


float age = 10;
float tmp = -1;

tmp = Engine->RegisterGlobalProperty("float age", (void*)&age);
std::cout << "tmp:" << tmp  << "\n";  // always ouputs "tmp:0" 

int id = Engine->GetGlobalVarIDByName("", "float age");
std::cout << "id:" << id << "\n";  // always ouputs "id:-15" 

// always outputs "Error!"
if(Engine->GetGlobalVarPointer(id, (void**)&tmp) < 0){
   std::cout << "Error!";
}

Any ideas? CD
Jesus is Lord!!
Advertisement
You should have to build the script first I thought before you can gain access to the variables in it?
Ahhh, that would have been nice to know before hand. Do I have to build the script everytime I set a new var, or just once before I set any?

Thanks!
CD
Jesus is Lord!!
Also,

You can see what the return codes mean by looking them up in angelscript.h



Also, WL, do you think that there might be a possibility of changing the return types to something like an Enum?
The return codes are also listed in the documentation. There are already defines for all of them - it's no different than an enum.
Hmm, I suppose you are right in that regard.

I was more considering the ability to do something like:

if( RetCode == ReturnCodes.InvalidConfiguration)
...
It'd be easy to make that enum yourself, but it wouldn't really make sense as part of the lib. I've always assumed witchlord went with the as prefix instead of a namespace in the first place for c compatibility. Does c have enums?
C has enums.
CD579:

Only script declared global variables can be retrieved with GetGlobalVarIDByXXX(). This is why you're getting a negative value for the id (negative values are errors).

The 'age' property is available directly to the application, since it registered it in the first place. Do you really need to retrieve it from the engine?

Rain Dog:

I could make the error codes into enums. But in many places a function returns either a negative value for an error or a positive value with another meaning, in which case the enums would be useless. For consistency I've left the error codes as normal constants.

You can still do

if( RetCode == asINVALID_CONFIGURATION )  ...


Deyja:

The 'as' prefix was chosen because of the coding style I use. It doesn't have anything to do with enums.

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

I didn't say it did. I didn't know if C had enums, so I was saying you may have decided not to use them to maintain C compatibility. :)

This topic is closed to new replies.

Advertisement