Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now
- - - - -

Question about value types

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 Grimshaw   Members   

687
Like
0Likes
Like

Posted 31 March 2013 - 03:16 PM

I have a doubt about angelscript that I need to clarify.

 

For lightweight classes which are efficiently passed by value, is there a way to still store handles to the object?

 

Explaining with an example: I have a Sprite class which is quite simple, having only a few members. I registered this as a Ref type because i wanted to pass it around through functions, modifying the original instance.

 

However, such a lightweight class could fit well as a value type , I believe... But if I do that, I am not sure I can still pass a sprite to a function(in-script) and modify the original Sprite object rather than its copy. Or can I?

 

Thanks in advance.


Indie Game Developer - Daeva Theory Studios

 

Twitter - Facebook

 

Next

Terra - rise of mankind

 

Previous

SFML Game Development (Book)


#2 SiCrane   Moderators   

11764
Like
0Likes
Like

Posted 31 March 2013 - 03:20 PM

You can pass a reference to the object. Ex: void foo(MyObject & inout).

#3 Grimshaw   Members   

687
Like
0Likes
Like

Posted 31 March 2013 - 08:57 PM

I mean inside the scripts.. Not from / to C++.

 

Sprite s;

 

changeThisSprite(@s); // or something similar


Indie Game Developer - Daeva Theory Studios

 

Twitter - Facebook

 

Next

Terra - rise of mankind

 

Previous

SFML Game Development (Book)


#4 Jake Albano   Members   

722
Like
0Likes
Like

Posted 01 April 2013 - 09:13 AM

You can only use object handles with reference types, but inout references will work with value types if you allow the script engine to use unsafe references.

engine->SetEngineProperty(asEP_ALLOW_UNSAFE_REFERENCES, true);

 

You can then use them inside scripts as well as passing tom C++.

void modify(Sprite & inout s)
{
    // modify the sprite
}

 

Be aware that you are now responsible for ensuring that parameters passed as inout remain valid for as long as they're in use. The script engine can't guarantee their lifetime, so it's possible to crash your application by passing temporary values into C++.


Edited by Jake Albano, 01 April 2013 - 09:13 AM.


#5 Grimshaw   Members   

687
Like
0Likes
Like

Posted 01 April 2013 - 04:00 PM

Thanks for the answer Jake! It clarifies things!


Indie Game Developer - Daeva Theory Studios

 

Twitter - Facebook

 

Next

Terra - rise of mankind

 

Previous

SFML Game Development (Book)





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.