ErikSwahn's Recent Forum Activity

  • The player can drop items. If 2 items collide they should make a new item. The items have a name variable telling the game what they are. How do I check the name of each one separately before deciding what to do when they collide?

    If item is overlapping item

    item 1 name is "STICK"

    item 2 name is "STICK"

    Then destroy item (both of them)

    Then spawn item and set name to "CLUB"

    I have tried sub events but it does not seem to work. I might have done it incorrectly since I am not 100% sure how to structure them though.

  • You do not have permission to view this post

  • > The swapping already works. This was tested before the system got more complex.

    >

    > However I will take your advice and make a check when something is picked up and run the loop afterwards. I will also try "else" to check if all slots are filled.

    >

    > Thanks!

    Oh okay, what isn't working?

    I figured out another way to solve it. If player overlaps an item and picks it up the item is destroyed, preventing actions further down the code. So I just placed each event in order in the sheet starting with if itemslot=3 then itemslot=4 etc.

    Like this:

    If player overlaps item

    Picks up

    itemslot=3

    itemslot=empty

    -set itemslot filled

    -destroy item

    If player overlaps item

    Picks up

    itemslot=4

    itemslot=empty

    -set itemslot filled

    -destroy item

    If player overlaps item

    Picks up

    itemslot=5

    itemslot=empty

    -set itemslot filled

    -destroy item

    Since the item is destroyed when one of these are true it simply stops the next event since the player is not overlapping item anymore.

    After these events I replaced the =empty with =filled and repeated the events but adding the replace actions.

    This works nicely since I will not have more than a maximum of 6 itemslots, so code won't be too long. Just thought I'd let you know how I solved it.

  • > The swapping already works. This was tested before the system got more complex.

    >

    > However I will take your advice and make a check when something is picked up and run the loop afterwards. I will also try "else" to check if all slots are filled.

    >

    > Thanks!

    Oh okay, what isn't working?

    I have not tried it yet since I must take a break and sleep. I am back at it tomorrow :)

  • Could you just have 3 global variables

    On pickup.

    Check slot 1.

    If global variable=0 then set global variable to uid of object picked up. Else check pickup2. Else check pickup3.

    The 3 slots will have uids set to them. And you can choose any object base on its uid

    On drop, just set the slot global variable to 0 again

    That sure is smart but I currently use instance variables for objects. Will try the "else" method later but must sleep first. Thanks for the simple idea :)

  • The swapping already works. This was tested before the system got more complex.

    However I will take your advice and make a check when something is picked up and run the loop afterwards. I will also try "else" to check if all slots are filled.

    Thanks!

  • Glad you are here lionz! I have tried to put these principles in but I think I am missing something fundamental.

    Here is a screenshot of what I have constructed so far. The item on the ground is destroyed but no item appear in the bag when I test. NONE means empty, not NONE means filled. The global variable called "itemslot" is just the current selected one, which should swap a filled slot. This should happen for a selected slot if all slots are filled. Itemslots currently start from 3 and reach 5, since first slots are for specific gear.

    picallow.com/events-2

  • When I pick up an item, I want to fill an empty slot. If I have 3 empty slots upon picking it up, just one of these must be filled instead of all 3.

    Since all the slots are same object and differentiate themselves only with a variable (1,2 or 3), I find it hard to check them all at the same time. If slot=1 is empty and slot=2 is empty just does not work since a slot is not both 1 and 2 at the same time. So I need to separate them in conditions and perhaps check them in steps.

    My mind want to structure it like this:

    if item picked up

    slot=1

    slot=empty (set to filled and stop checking)

    slot=2

    slot=empty

    slot=3

    slot=empty

    if item picked up

    slot=1

    slot=filled (check next)

    slot=2

    slot=empty (set to filled stop checking)

    slot=3

    slot=empty

    Does sub events solve this? If so, how should I structure it?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for the explanation! In that case I will make the layer non global and rework some things. It is better that way.

    Cheers :)

  • It worked but now I have a new problem. Since the objects are global and belong to a global layer, another object is created when I transition between layouts. So if there are 6 itemslots, they become 12 when I enter a new layout.

    If I move the object to a non global layer it fixes this but I have some other reasons for them to stay on a global layer. Is there no other fix to this? Should I remove the persist behaviour?

    Appreciate the help!

  • I have some object sprites that symbolize equipment. They all have a number for which slot they are. "Slot 1" for example is the weapon slot. The weapon is set depending on what "Slot 1" contains (what name a variable has).

    If slot1.name=none set weapon to "none".

    When I pick up a weapon it sets slot1.name to the weapon.name (shortsword).

    Which sets slot1.name=shortsword.

    All these objects are on a global layer and they have persist. Yet they reset to their original state if I leave a layout.

    So each time I leave a layout, slot1.name becomes "none" which is it's default state.

    How can I fix this issue?

    EDIT: I noticed when I went back to a layout I picked up a weapon in, it saved that state. But why does it not bring this state over to another layout?

  • Excellent. Thank you :)

ErikSwahn's avatar

ErikSwahn

Member since 15 Jul, 2014

Twitter
ErikSwahn has 1 followers

Trophy Case

  • 10-Year Club
  • RTFM Read the fabulous manual
  • Email Verified

Progress

12/44
How to earn trophies