Is there any noticeable advantage to making a variable available to only one sprite? For example, will it reduce lag or game size? Thanks in advance.
Offline
I think its just so if you make a game with lots of variables, you don't have a hard time finding the right one.
Offline
Shruikan42 wrote:
Is there any noticeable advantage to making a variable available to only one sprite? For example, will it reduce lag or game size? Thanks in advance.
I addition if a variable indicates status for that sprite alone (for example if the sprite is walking or running could be stored in a variable in the spite then you just duplicate the sprite and don't have to change anything).
The only thing I don't get if is this is a 'variable question' why does it always read the same every time I load it.
Offline
Mike_W wrote:
Shruikan42 wrote:
Is there any noticeable advantage to making a variable available to only one sprite? For example, will it reduce lag or game size? Thanks in advance.
I addition if a variable indicates status for that sprite alone (for example if the sprite is walking or running could be stored in a variable in the spite then you just duplicate the sprite and don't have to change anything).
The only thing I don't get if is this is a 'variable question' why does it always read the same every time I load it.
I don't understand what you say. What does duplicating a sprite have to do with a variable storing information for that sprite alone? Do you mean that duplicating a sprite duplicates all variables which belong to it?
I have no idea what you're talking about in your last sentence. Could you explain more?
Offline
bosox397 wrote:
I think its just so if you make a game with lots of variables, you don't have a hard time finding the right one.
Let's say you are going to make a lot of duplicate enemy sprites that each take 5 hits to kill. When you are writting your scripts for the enemy sprite, you would want to make a variable that can be seen by that sprite only to keep track of the number of times it has been hit. You might call it "Hit Count" or something. Then, when you duplicate the sprite to make an army of enemies, each enemy sprite will have it's own version of the Hit Count variable that only they can see. Changing the value of one will have no impact on the value of all the others.
That's one example of why you might want to use the "for this sprite only" option when making a variable. In general, it's good programming practice to avoid the use of global variables (variables that can be changed by any sprite) as much as possible as they can make your code hard to understand - just because they can be changed anywhere. So I use the "for this sprite only" option a lot and use the sensing block to read "for this sprite only" values from other sprites - but not change the value!
I hope that wasn't too confusing.
Offline
Shruikan42 wrote:
[
I have no idea what you're talking about in your last sentence. Could you explain more?
The last sentence was a joke (pun). If the question is variable doesn't that mean it should change. Just like all the people that have moving sales - but they are at the same address all day,
Offline
Mike_W wrote:
Shruikan42 wrote:
[
I have no idea what you're talking about in your last sentence. Could you explain more?The last sentence was a joke (pun). If the question is variable doesn't that mean it should change. Just like all the people that have moving sales - but they are at the same address all day,
Oh, now I get it Variables change, the question doesn't.
Thanks for the info, Bosox and Paddle2See.
Another question, though, are non-global variables simply for convenience or do they actually help the project?
Last edited by Shruikan42 (2009-04-12 05:51:15)
Offline