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

#1 2012-03-06 16:25:56

sidthekoala
New Scratcher
Registered: 2012-03-06
Posts: 15

Variable changes forever?

I have made my game so that when the Burger Sprite is touching is touching the plate, the variable for the plate which shows the calorie value goes up by 600 and when it is taken off the plate it decreases by 600. However when I put the Burger on the plate the calorimeter reading keeps increasing past 600 eventually going into the millions by adding 600 repeatedly because of the forever function. I have tried using broadcasts but they broadcast forever and the same effect happens. I have also had some success with stop script but that doesn't allow me to add other foods to the plate. Could you please suggest a solution?

Offline

 

#2 2012-03-06 16:31:43

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Variable changes forever?

Perhaps on the plate sprite, you can have these scripts:

when gf clicked
forever
set [calories v] to [0]
if <touching [burger v]?>
change [calories v] by [600]
end
if <touching [fries v]?>
change [calories v] by [400]
end
if <touching [salad v]?>
change [calories v] by [300]
end
This way the "calories" variable (or whatever you want to name it) will constantly be updated based on if it is touching the different foods.  smile


http://i.imgur.com/WBkM2QQ.png

Offline

 

#3 2012-03-06 21:41:34

DaScratcher101
Scratcher
Registered: 2012-02-16
Posts: 41

Re: Variable changes forever?

Very simple.

When gf clicked
forever
if <[touching sprite Burger? v]>
change [calories v] by [600]
if <[calories v] > [600]>
set [calories v] to [600]
stop script
end

Offline

 

#4 2012-03-06 21:46:57

DaScratcher101
Scratcher
Registered: 2012-02-16
Posts: 41

Re: Variable changes forever?

Lucario621 wrote:

Perhaps on the plate sprite, you can have these scripts:

when gf clicked
forever
set [calories v] to [0]
if <touching [burger v]?>
change [calories v] by [600]
end
if <touching [fries v]?>
change [calories v] by [400]
end
if <touching [salad v]?>
change [calories v] by [300]
end
This way the "calories" variable (or whatever you want to name it) will constantly be updated based on if it is touching the different foods.  smile

That won't work because it will forever change by 600 without stopping as long as the burger is on the plate. He is trying to explain that that's happening. 8)

Offline

 

#5 2012-03-06 22:45:21

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Variable changes forever?

when gf clicked
forever
if <touching [plate]?>
change [calories] by (600)
wait until <not <touching [plate]?> >
change [calories] by (-600)
end
end


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2012-03-07 12:06:38

sidthekoala
New Scratcher
Registered: 2012-03-06
Posts: 15

Re: Variable changes forever?

MoreGamesNow wrote:

when gf clicked
forever
if <touching [plate]?>
change [calories] by (600)
wait until <not <touching [plate]?> >
change [calories] by (-600)
end
end

Sorry but this does not work. When the burger is taken off the plate it keeps decreasing forever.

Offline

 

#7 2012-03-07 12:14:31

sidthekoala
New Scratcher
Registered: 2012-03-06
Posts: 15

Re: Variable changes forever?

DaScratcher101 wrote:

Very simple.

When gf clicked
forever
if <[touching sprite Burger? v]>
change [calories v] by [600]
if <[calories v] > [600]>
set [calories v] to [600]
stop script
end

I have tried this, however I couldnt find a red sensing function and it did not change the variable. Sorry, any other suggestions?

Offline

 

#8 2012-03-07 13:41:22

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Variable changes forever?

sidthekoala wrote:

MoreGamesNow wrote:

when gf clicked
forever
if <touching [plate]?>
change [calories] by (600)
wait until <not <touching [plate]?> >
change [calories] by (-600)
end
end

Sorry but this does not work. When the burger is taken off the plate it keeps decreasing forever.

Then you either wrote that script out wrong or there's another script somewhere else that's interfering.


Why

Offline

 

#9 2012-03-07 17:22:15

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Variable changes forever?

RedRocker227 wrote:

sidthekoala wrote:

Sorry but this does not work. When the burger is taken off the plate it keeps decreasing forever.

Then you either wrote that script out wrong or there's another script somewhere else that's interfering.

Make sure the "change [calories] by (-600)" is inside the if-statement.

P.S. I just viewed the block-thing in internet explorer for the first time, and it doesn't look nearly as good as on firefox and/or chrome.  On the other hand, I'm using using a PC to view the Scratch website for the first time.  Wonder what the problem is.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#10 2012-03-07 17:33:59

DaScratcher101
Scratcher
Registered: 2012-02-16
Posts: 41

Re: Variable changes forever?

sidthekoala wrote:

DaScratcher101 wrote:

Very simple.

When gf clicked
forever
if <[touching Burger? v]>
change [calories v] by [600]
if <[calories v] > [600]>
set [calories v] to [600]
stop script
end

I have tried this, however I couldnt find a red sensing function and it did not change the variable. Sorry, any other suggestions?

That's what I meant. Try it now.

Offline

 

#11 2012-03-08 13:30:49

sidthekoala
New Scratcher
Registered: 2012-03-06
Posts: 15

Re: Variable changes forever?

RedRocker227 wrote:

sidthekoala wrote:

MoreGamesNow wrote:

when gf clicked
forever
if <touching [plate]?>
change [calories] by (600)
wait until <not <touching [plate]?> >
change [calories] by (-600)
end
end

Sorry but this does not work. When the burger is taken off the plate it keeps decreasing forever.

Then you either wrote that script out wrong or there's another script somewhere else that's interfering.

I tried this again and deleted the variable and made it again. It seemed as if it was corrupt somehow. Anyway, it's working now. Thank You very much.

Offline

 

Board footer