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

#1 2012-04-23 16:12:38

Babado
Scratcher
Registered: 2011-09-15
Posts: 84

"Chest" script

Hey there, i'm looking for a chest script. Or a inventory script eitheir way

What I want it to do is-

Once the hero gets so close to this box, and pressed said key, it will check his inventory for all items that are needed to complete the level/game. If the player has all of them, it will come up with a finish screen, if not, it tells him he doesn't have the required items.

I've experimented with many things and could find nothing that worked as effective as I would like it to.

Offline

 

#2 2012-04-23 18:13:38

Babado
Scratcher
Registered: 2011-09-15
Posts: 84

Re: "Chest" script

Bumpity bump

Offline

 

#3 2012-04-23 18:48:17

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: "Chest" script

Babado wrote:

Hey there, i'm looking for a chest script. Or a inventory script eitheir way

What I want it to do is-

Once the hero gets so close to this box, and pressed said key, it will check his inventory for all items that are needed to complete the level/game. If the player has all of them, it will come up with a finish screen, if not, it tells him he doesn't have the required items.

I've experimented with many things and could find nothing that worked as effective as I would like it to.

Hey there Babado!  big_smile
You need to make a script on the chest sprite which will check to see if the player if close enough and the key is pressed. (Note that if you're game is using scrolling then this may not work correctly)

Forever if (Distance to [player] is less than (<) 50 AND key [x] is pressed

You can replace the '50' with whatever distance fits your game.
After this you need to check if the player has all of the items, the best way to do this is to add collected items to a list. You can create a list called 'inventory' and when the player collects an item, then the item is added to the inventory list. You can then check if the player has the items by putting an 'if else' statement in the script above.

IF 'inventory' contains [Sword] and 'inventory' contains [Potion of Healing]
     Broadcast [Display Win Screen]
ELSE
     think [I might need more items to complete this quest...] for (5) secs

I hope this works and also makes sense to you  smile
Good luck!

(Note - if anyone can replace my Script with Scratchblocks then please take the time to do so! - Prestige)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#4 2012-04-23 19:08:07

Babado
Scratcher
Registered: 2011-09-15
Posts: 84

Re: "Chest" script

Prestige wrote:

Babado wrote:

Hey there, i'm looking for a chest script. Or a inventory script eitheir way

What I want it to do is-

Once the hero gets so close to this box, and pressed said key, it will check his inventory for all items that are needed to complete the level/game. If the player has all of them, it will come up with a finish screen, if not, it tells him he doesn't have the required items.

I've experimented with many things and could find nothing that worked as effective as I would like it to.

Hey there Babado!  big_smile
You need to make a script on the chest sprite which will check to see if the player if close enough and the key is pressed. (Note that if you're game is using scrolling then this may not work correctly)

Forever if (Distance to [player] is less than (<) 50 AND key [x] is pressed

You can replace the '50' with whatever distance fits your game.
After this you need to check if the player has all of the items, the best way to do this is to add collected items to a list. You can create a list called 'inventory' and when the player collects an item, then the item is added to the inventory list. You can then check if the player has the items by putting an 'if else' statement in the script above.

IF 'inventory' contains [Sword] and 'inventory' contains [Potion of Healing]
     Broadcast [Display Win Screen]
ELSE
     think [I might need more items to complete this quest...] for (5) secs

I hope this works and also makes sense to you  smile
Good luck!

(Note - if anyone can replace my Script with Scratchblocks then please take the time to do so! - Prestige)

Anyway to include more than one and? I have about four items I need to store

Offline

 

#5 2012-04-23 19:19:51

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: "Chest" script

Sure! You can stack and's infinitely. In the 2 spaces in each AND, just add another AND until you have as many as you need  smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#6 2012-04-24 15:15:50

Babado
Scratcher
Registered: 2011-09-15
Posts: 84

Re: "Chest" script

Prestige wrote:

Sure! You can stack and's infinitely. In the 2 spaces in each AND, just add another AND until you have as many as you need  smile

Thanks, one more question. I have two items called "Wood" both the same. If I set it to pick up both wood, will it realize that they only have one? Or will it cause problems as they are named the same?


Forever if
Distance to hero
less than 50
AND

Doesn't work, I can't put a and in the less than box without it not working.

Last edited by Babado (2012-04-24 17:01:13)

Offline

 

#7 2012-04-25 11:16:27

Babado
Scratcher
Registered: 2011-09-15
Posts: 84

Re: "Chest" script

Bump

Offline

 

#8 2012-04-25 11:37:37

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: "Chest" script

Babado wrote:

Thanks, one more question. I have two items called "Wood" both the same. If I set it to pick up both wood, will it realize that they only have one? Or will it cause problems as they are named the same?


Forever if
Distance to hero
less than 50
AND

Doesn't work, I can't put a and in the less than box without it not working.

If you have 2 items called the same name, it could cause an issue, you may need to calle them 'wood1' and 'wood2' and check for both. If you don't want to do this, you could set up a script where it checks each of the items individually and counts them.

To do this, create 2 new variables called 'counter' and 'tally'.

Then this script:
(when distance to player < 50 AND key 'x' pressed etc)
set counter to 1
set tally to 0

[REPEAT (length of 'inventory')
        [if item counter of inventory = wood
                change tally by 1]
if tally = 2
        broadcast win
ELSE
         broadcast 'need more stuff'


change counter by 1 ]
         

Oh, and you need to put the distance to thing in the lesser than box, and then the lesser than box in the AND box


<(distance to [x]) < [50]> 
AND if key 'x' pressed
(you can put the green box above into the AND box  smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#9 2012-04-29 00:20:05

Babado
Scratcher
Registered: 2011-09-15
Posts: 84

Re: "Chest" script

Would you be able to put that script in block form, Prestige? I have tried re-creating it from the text you left but it doesn't seem to work.

Last edited by Babado (2012-04-29 00:21:48)

Offline

 

#10 2012-04-29 08:35:44

hydreigon
New Scratcher
Registered: 2011-07-20
Posts: 23

Re: "Chest" script

when gf clicked
forever
if <touching [hero]>
say [I will never get the hang of scripts in posts.] for (3) secs

Offline

 

Board footer