How do I fix this code?

  • I am working on my own inventory system. I have tried different ways to make this work.

    When I use this code:

    What it does is:

    - if inventory is empty, it adds to the first slot just fine.

    - if the same item frame exists in the inventory, it adds the numb fine but ALSO creates a new item in the next slot and adds 1 as if the inv hadnt the item at all.

    So, I believe my "Else" is not correct, as it is supposed to return false for first, or if the first is true, is it not supposed to neglect the second statement?

    Thank you for your help :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Your Else condition is hanging, it does nothing. Try changing it like this:

    ...
    Else
     System pick All invItems
     invItems compare animation frame=0
     invItems pick with lowest slot
    	.........
    
  • Ahhh I gotcha. So if I code it with the picking all inside the same condition it works :)

    If I code it where pick all is a sub-event, it doesn't.

    Are we not allowed to have "Else" condition without another condition unless its a Boolean to the first condition then?

    I read that when using "Else" we cant define a different comparable condition, that it has to be the opposite of the first condition (true, false).

    But doing it this way lets us compare more advanced conditions it seems, which I need! hehe

    I get that having to pick all first works before picking frame and then slot :)

    Thank you for the help :)

  • Are we not allowed to have "Else" condition without another condition unless its a Boolean to the first condition then?

    On your screenshot the "Else" event was simply empty, it had no sub-events or actions, that's why it did nothing. The next condition after it was not a sub-event under Else, that's why a new item in a new slot was always created.

    .

    Else with boolean conditions works the same way as in many other languages.

    But when you use Else with events that pick instances, Else means "if previous event picked nothing". Actually, you don't need to pick all inside of Else block in this case.

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