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

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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?

  • 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.

  • 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...

  • 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.

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for help, guys! It'll take me a bit to wrap my brain around the info.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)