This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-17 11:59:38

killerchip
New Scratcher
Registered: 2012-08-02
Posts: 8

cross sprite variable changes

When I'm building a sprite, I always try to make it as 'independent' as possible, so it can be replicated and re-used in other project with minimum code changes during 'copy'.

for example I have a spaceship in a shoot-em-up game and I want it to appear in screen in different positions each time I call it to 'launch'. So I create in the sprite the internal initx and inity variables. But the launcher object cannot 'modify' these variables for my sprite.

I know that one suggestion is to make the variables global, but when I want to replicate the sprite to create a second, third, etc. enemy, their 'global' initx and inity will conflict.

It would be good to have a reverse variable sensor to say
set 'variable of object' to value (similar to the way you can read the value).

What I'm doing right now is use a list of global initx and inity and have my sprite copies have a different index and read initial values from there. But it's not so elegant.

Anyone bump onto this? Or found an elegant solution?

Offline

 

#2 2012-08-17 20:22:35

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: cross sprite variable changes

You can use all local variables, and then in each sprite, add it to a list.


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#3 2012-08-17 22:24:30

dvd4
Scratcher
Registered: 2010-06-30
Posts: 1000+

Re: cross sprite variable changes

killerchip wrote:

When I'm building a sprite, I always try to make it as 'independent' as possible, so it can be replicated and re-used in other project with minimum code changes during 'copy'.

for example I have a spaceship in a shoot-em-up game and I want it to appear in screen in different positions each time I call it to 'launch'. So I create in the sprite the internal initx and inity variables. But the launcher object cannot 'modify' these variables for my sprite.

I know that one suggestion is to make the variables global, but when I want to replicate the sprite to create a second, third, etc. enemy, their 'global' initx and inity will conflict.

It would be good to have a reverse variable sensor to say
set 'variable of object' to value (similar to the way you can read the value).

What I'm doing right now is use a list of global initx and inity and have my sprite copies have a different index and read initial values from there. But it's not so elegant.

Anyone bump onto this? Or found an elegant solution?

+1


I made a mod  big_smile  It's called blook!
http://i49.tinypic.com/16ia63p.png

Offline

 

Board footer