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

#1 2012-09-21 17:34:01

DurkaDerper
New Scratcher
Registered: 2012-09-21
Posts: 1

How to make Variables not go into negatives

Hello,
For my Computer Science class we have been asked to make a gun and i choose to make an FPS but have run into trouble with an ammo system. The weapon right now has an auto reload set to 0 so when it is at 0 it automatically reloads, but I have to stop there for it to work. So I am asking both a.) how to stop a variable going into negatives and b.) how to set something to react if a variable is between zero and a negative number. I would gracious for any reply

Offline

 

#2 2012-09-21 17:42:18

jamiewinter
Scratcher
Registered: 2012-08-19
Posts: 100+

Re: How to make Variables not go into negatives

to make it reload do this

when space key pressed
if ammo=0
set ammo 5
else
change ammo by -1
do whatever you do to fire
wait 0.1 seconds


hope it helped  smile

Last edited by jamiewinter (2012-09-21 17:46:58)


Check out my youtube channel http://www.youtube.com/user/axelregulator/featured

Offline

 

#3 2012-09-21 17:46:42

jamiewinter
Scratcher
Registered: 2012-08-19
Posts: 100+

Re: How to make Variables not go into negatives

or you could do

when flag is clicked
forever
if
key space pressed
repeat until ammo=0
{do whatever to fire
{change ammo by -1
set ammo to 5


Check out my youtube channel http://www.youtube.com/user/axelregulator/featured

Offline

 

#4 2012-09-21 18:17:35

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to make Variables not go into negatives

To make sure that the gun doesn't shoot with out ammo, and to make sure that it reloads, just add this to the gun's scripts:


if <(ammo) > (0) >
 Gun's scripts
else
 reload scripts
end
I hope that this helps!


http://i46.tinypic.com/35ismmc.png

Offline

 

#5 2012-09-21 18:20:23

jamiewinter
Scratcher
Registered: 2012-08-19
Posts: 100+

Re: How to make Variables not go into negatives

i think mine would work anyway but...
dont argue with a pro


Check out my youtube channel http://www.youtube.com/user/axelregulator/featured

Offline

 

#6 2012-09-21 18:27:23

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to make Variables not go into negatives

jamiewinter wrote:

i think mine would work anyway but...
dont argue with a pro

Your second script would work, so good job on thinking of it (  big_smile  ), though it could be improved upon.


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer