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

#1 2012-01-30 19:33:11

Leo_the_Lion
Scratcher
Registered: 2008-10-23
Posts: 66

Inventory Help?

I'm working on an RPG, and of course I have an inventory list and all. So I was wondering, how would I get one of the items to be deleted at some point, like a health potion disappearing once you drink it?

Offline

 

#2 2012-01-30 19:37:32

hello12345678910
Scratcher
Registered: 2009-07-11
Posts: 100+

Re: Inventory Help?

Ok. So Lets Say We Have This List:

1.Sword
2.Shield
3.Potion
4.Bow
5.Quiver

First check if the potion's there:

<[items v] contains [Potion]>
Use
Delete [4 v] of [Items v]
The list will then be

1.Sword
2.Shield
3.Bow
4.Quiver

Removing the potion shifts the rest up 1

Last edited by hello12345678910 (2012-01-30 19:38:22)


http://tinyurl.com/8yt32o9 http://tinyurl.com/6tgwp5r || Fish = F+I+S+H = 6+9+19+8 = 42<<The answer to Life, the Universe and Everything

Offline

 

#3 2012-01-30 19:42:54

Leo_the_Lion
Scratcher
Registered: 2008-10-23
Posts: 66

Re: Inventory Help?

I knew that, but thanks anyway for replying this soon. What I want to know is how to make the game find out where the potion is in the list, in order to then use that process to delete it.

Offline

 

#4 2012-01-30 19:52:54

hello12345678910
Scratcher
Registered: 2009-07-11
Posts: 100+

Re: Inventory Help?

Leo_the_Lion wrote:

I knew that, but thanks anyway for replying this soon. What I want to know is how to make the game find out where the potion is in the list, in order to then use that process to delete it.

Sorry. Try this:

set [itemtofind v] to [Potion]
set [count v] to [1]
Repeat (length of [items v])
if <(item (count) of [items v]) = (itemtofind)>
set [itemposition v] to (count)
end
change [count v] by (1)
the position of Potion will be set to Itemposition

if the list is REALLY long (probably not though, like 50 items  tongue ) Try this:

set [itemtofind v] to [Potion]
set [count v] to [1]
set[length v] to (length of [items v])
set [end v] to (0)
repeat until <<(count) = (length)> or <(end) = (1)>>
if <(item (count) of [items v]) =(itemtofind)>
set [itemposition v] to (count)
end
change [count v] by (1)
set [end v] to (1)

Last edited by hello12345678910 (2012-01-30 19:58:52)


http://tinyurl.com/8yt32o9 http://tinyurl.com/6tgwp5r || Fish = F+I+S+H = 6+9+19+8 = 42<<The answer to Life, the Universe and Everything

Offline

 

#5 2012-01-30 19:57:16

Leo_the_Lion
Scratcher
Registered: 2008-10-23
Posts: 66

Re: Inventory Help?

Thanks, very helpful! This is really going to come in handy A LOT.

Offline

 

#6 2012-01-30 20:01:07

hello12345678910
Scratcher
Registered: 2009-07-11
Posts: 100+

Re: Inventory Help?

Leo_the_Lion wrote:

Thanks, very helpful! This is really going to come in handy A LOT.

Yes, Your welcome. it can be used to search anything, and can also be used to do things to every item of the list individually. it also can be used for other things too, its a useful skill to learn.


http://tinyurl.com/8yt32o9 http://tinyurl.com/6tgwp5r || Fish = F+I+S+H = 6+9+19+8 = 42<<The answer to Life, the Universe and Everything

Offline

 

Board footer