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

#1 2007-06-03 23:12:10

Robobob
Scratcher
Registered: 2007-06-03
Posts: 7

How to use a item when you buy it

How do you make it so that you can only use items when you buy them.( In a game)

Offline

 

#2 2007-06-04 00:38:45

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: How to use a item when you buy it

Have a variable (maybe called "bought") that you set to something other than zero when you have bought it.  Use "if bought >0 " tests around any actions.

Offline

 

#3 2007-06-04 02:06:07

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: How to use a item when you buy it

Or, to avoid variables, hide the sprite and only show it when it is bought in an interaction with an unconnected sprite.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#4 2007-06-05 17:22:44

mungojelly
Scratcher
Registered: 2007-05-19
Posts: 35

Re: How to use a item when you buy it

Here's an idea for how to do this: You could have a "bag" on the screen that shows what items you have, and move an item to the bag when you buy it.  Then you could test whether the item was touching the color of the bag to see whether they have it yet or not.

<3

Offline

 

#5 2007-06-05 17:55:22

boinoinoi
Scratcher
Registered: 2007-06-05
Posts: 500+

Re: How to use a item when you buy it

for example, if the item was an axe that cost 100 money things, then
try this:
when I recieve [buy axe]
if<(money>100)>
set axe's bought to (1)
change money by (-100)
else
say [not enough money]

When I recieve [use axe]
if<(bought=1)[/blocks]>
broadcast [axe used]
change enemy health by (pick random(15)to(20))
if<(bought=0)[/blocks]>
say [you don't have the axe]for(2)secs

Last edited by boinoinoi (2008-04-24 09:54:49)


http://i30.tinypic.com/335fpxx.jpg
"Boinoinoi is the only person on the forums that I expect to be wearing a monocle all the time behind that screen, so I'm sure being as classy as he is, he knows what he's doing"        http://myfastcounter.com/count.php?c_style=88&amp;id=1284259111http://myfastcounter.com/count.php?c_style=88&amp;id=1286068127

Offline

 

Board footer