How do I lose items after being hit by enemies?

Get help using Construct 2

Post » Thu Dec 22, 2016 8:35 pm

First I'll say I apologize if this topic has already been discussed/solved. I have searched for a topic on this for quite some time and I find things that are close, but I need a more specified answer. I will also say I'm fairly new to Construct 2. I've used the free version off and on the past few years and I finally bought it a couple of weeks ago.

Here is my issue:
In my game you collect items and bring them back to a hoard. You can only store 10 items total in your "inventory" to bring back. If you are hit by any enemies you drop all your items just like Sonic's damage system. I somehow have a spawning system for bees (the enemies in my game) working exactly the way I want it too. Despite using similar compare variable system events I can't get the player to drop the amount of items that are counted in its "inventory". If anyone is able to help me with this problem I would be very grateful. I'll post the file if someone wants to see it. Only reason I haven't is because I want to learn what I am doing wrong and not just have someone hot fix it for me. Thanks in advance!
B
3
Posts: 3
Reputation: 181

Post » Fri Dec 23, 2016 11:45 am

How does your inventory work? eg; Is it object-based? Is data held in an array? Is it just a set of ten variables?

What behaviour is currently exhibited - do they drop one of their items, none of their items, do they drop items they don't have?

Your games sounds fun by the way :)
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 247
Reputation: 2,318

Post » Fri Dec 23, 2016 12:52 pm

Well on the bottom left corner (in game) It displays 2 boxes that fill up with five items each. When one inventory's instance variable is equal to 5. The second box will start filling up until its instance variable is equal to 5. I'd say its a mixture of both variables and object based since for each item that I collect it does display itself in my inventory. I have never used arrays.

It's pretty random whats dropped. It's either more than ten is dropped or a few is dropped.

Thanks! It was a fun little idea I came up with to help me learn the program a bit more.
B
3
Posts: 3
Reputation: 181

Post » Sat Dec 24, 2016 12:52 pm

You'll want to learn arrays - they're tricky at first, but the gateway to much more powerful stuff! And they're a lot simpler than you think - an array is essentially a basic spreadsheet (Imagine the 'Z' axis as being 'Sheets' on the spreadsheet).

Back to your problem: you you could try

on [player] collision with [enemy]
for each [item]
where [item] is overlapping [inventorybox]
>>> drop items (however that works)

That should identify your items one-by-one for you, and make it easy to create the necessary logic to create the dropped items on the floor.
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 247
Reputation: 2,318

Post » Mon Jan 09, 2017 1:02 pm

It's funny you recommended Arrays I am putting aside that game to work on learning Arrays and Functions. I will try your idea for my inventory problem, but like you said Arrays seem to be the answer to my problem. Are their any tutorials you would recommend?
B
3
Posts: 3
Reputation: 181


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 26 guests