Jump to content
  • Advertisement
Sign in to follow this  
CD579

Setting and Getting a Global Var

This topic is 4518 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
The return codes are also listed in the documentation. There are already defines for all of them - it's no different than an enum.

Share this post


Link to post
Share on other sites
Hmm, I suppose you are right in that regard.

I was more considering the ability to do something like:

if( RetCode == ReturnCodes.InvalidConfiguration)
...

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!