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

#1 2013-01-15 19:10:30

pigswithguns
New Scratcher
Registered: 2013-01-15
Posts: 4

pickup items

i am making a game where i would like to be able to make items that can only get in the players inventory by passing over the item also im not to sure i know how to make a inventory

Offline

 

#2 2013-01-15 19:24:33

numberonegamers
Scratcher
Registered: 2012-07-12
Posts: 100+

Re: pickup items

When gf clicked
Delete [all] of [list v]
Forever
 If <touching [sprite you want it to touch v] >
  Add [item name that player just touched] to [list v]
  Hide
 End
End

Last edited by numberonegamers (2013-01-15 19:25:25)

Offline

 

#3 2013-01-16 18:15:09

pigswithguns
New Scratcher
Registered: 2013-01-15
Posts: 4

Re: pickup items

that will help with keys and such but i want to be able to also get the items from the inventory

Offline

 

#4 2013-01-16 18:21:06

pigswithguns
New Scratcher
Registered: 2013-01-15
Posts: 4

Re: pickup items

i also think i have a way of doing it will this work

[ scratchblocks ]
when gf clicked
if touching < sprite 1 >
brodcast [ inventory ]
hide

Offline

 

#5 2013-01-16 21:49:32

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: pickup items

pigswithguns wrote:

that will help with keys and such but i want to be able to also get the items from the inventory

I answered the exact same question in the Spanish forum. What you need to do, is determine what particular item the player wants, and check every single item in the list, to see if it's what the player asked for. If so, something happens and the item can then be deleted. Here's one way to go about it:

when I receive [use item v]
ask [Which item?] and wait //see what item the player wants
set [i v] to [1] //reset iterator variable.
repeat (length of [Backpack v]) //for each item in the Backpack...
    if <(item (i) of [Backpack v]) = (answer)> //if it's the one the player wants...
        if <(item (i) of [Backpack v]) = [food]> //check if it's this particular item,
            broadcast [food v] //do the respective action,
            delete (i) of [Backpack v] //and delete it (it's a consumable)
        end
        if <(item (i) of [Backpack v]) = [magic ball]> //example of non-consumable
            broadcast [magic ball v]
        end
        stop script //we found what we wanted, so we break the loop
    end
    change [i v] by [1] //if it isn't the item we want, check next item
end
say [You don't have that item!] for (2) secs //this will happen only if the loop isn't broken; i.e. we didn't find the item


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

Board footer