• Advertisement
Sign in to follow this  

Properties in AngelScript

This topic is 4882 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

Hi, I think it would be great if AngelScript supported properties (a kind of variables, which are accessed via pair of Get/Set functions). The actual variable may not even exist at all. Consider the following example: Let's say we have an in-game console and player has a [limited] access to internal game variables. Wouldn't it be nicer to let him type like: [CONSOLE] game.maxPlayers 32 when he wants to set the max number of players instead of clumsy [CONSOLE] game.SetMaxPlayers( 32 ) ? Of course it is possible to export variable maxPlayers through RegisterObjectProperty(), but what if this variable is not allowed to be changed at any time (and/or some action is required to be taken upon its change)? Cheers, RCL

Share this post


Link to post
Share on other sites
Advertisement
You could use a class type with an assignment operator to emulate the setting behavior. Catching gets is more difficult. I'd do it in C++ with a copy constructor. The copy is 'getting' the value of the source. Whenever you pass by value the copy constructor is called. SomeClass.Member won't call it, but as soon as you try and store it or use it in any way, it will be called.

Share this post


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

  • Advertisement