Can I use a variable's value to select a variable?

Just started using Construct 2? Post your questions here

Post » Tue Aug 26, 2014 8:23 am

Sorry for confusing thread title. :/

I have an event where one randomly-chosen sandwich from an inventory pool of five must be burned, but a user does not have to have all sandwiches in his inventory. Therefor, I need to check to make sure the sandwich exists to be burned before I actually burn it.

What I'm trying to do:
IF "event triggers," THEN set BurnedSandwich to floor(random(1,6))

IF BurnOneSandwich=1 AND ("SandwichSlot"&BurnedSandwich&"Filled") = 1
THEN "set BurnOneSandwich to 0, burn the sandwich, tell the user which sandwich burned, yadayadayada."
ELSE Set BurnedSandwich to floor(random(1,6))


Can I actually use ("SandwichSlot"&BurnedSandwich&"Filled") or is there some other way of keeping this simple and in one event?
B
4
Posts: 5
Reputation: 210

Post » Tue Aug 26, 2014 9:02 am

Do only sandwiches that are in the inventory exist, or are there sandwiches existing that are not yet in the inventory?
Edit: I assume the latter as it would be trivial otherwise.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Aug 26, 2014 9:08 am

codah wrote:Do only sandwiches that are in the inventory exist, or are there sandwiches existing that are not yet in the inventory?

Only sandwiches in the inventory exist. The components of the sandwiches are selected by users, with the selected components committed to the "inventory" as "a sandwich." (technically, there is no unified sandwich, just a bunch of committed variables which go in the next unfilled slot of the inventory screen, which is a table.)

So it looks more like:
Slot 1 (occupied) - Bologna - Am. Cheese - Peppers - Mustard - Sell (enabled)
Slot 2 (empty) - "" - "" - "" - "" - Sell (disabled)
Slot 3 (empty) - "" - "" - "" - "" - Sell (disabled)
Slot 4 (empty) - "" - "" - "" - "" - Sell (disabled)
Slot 5 (occupied) - Mustard - Lettuce - Bacon - Mayo - Sell (enabled)

ETA: So I don't come off as a complete asshole, I tried what I thought up in OP and it didn't work.
ETA2: -And I think I responded to your question incorrectly. "Pre-made" sandwiches don't already exist, but they can come into existence. Gosh, this is a pretty high-level conversation about sandwiches... :lol:
B
4
Posts: 5
Reputation: 210

Post » Tue Aug 26, 2014 9:28 am

I would design this with containers, i.e. all sandwich components in a container. Then just pick a random number based on filled slots, pick an item from that inventory slot (which picks all other items in the same container) and destroy one of them; this destroys them all.

Edit: and don't worry, I have a half finished (well maybe one tenth finished) sandwich making game as well.

Edit 2: when I say destroyed, you probably don't want to destroy them, but all components are still picked and you can 'burn' them or whatever.
Last edited by codah on Tue Aug 26, 2014 11:49 am, edited 1 time in total.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Aug 26, 2014 9:36 am

Kuln wrote:is there some other way of keeping this simple and in one event?


1 Event - lol, lets try...

Create a Variable CheckSandwich = 0
Now Set CheckSandwich = Variable1>0 & Variable2>0 & Variable3>0?1:0
This returns 1 if var1 and var2 and var3 > 0 and returns 0 unless all are greater than 1

Now you can
If CheckSandwich >0 do your burn here

Here are some native expressions.
& is and
| is or

etc

edit: example added
You do not have the required permissions to view the files attached to this post.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Tue Aug 26, 2014 10:17 am

Thanks for help, guys! It'll take me a bit to wrap my brain around the info.
B
4
Posts: 5
Reputation: 210


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 6 guests