How do I apply my function to the right slot?

0 favourites
  • 7 posts
From the Asset Store
A slots game template designed to be skin-able for mobile
  • Hello everyone!

    I'm in trouble with a function problem. I have for my game two slots for my power-ups. Each one can be activated with a button, "Y" for slot_1 and "B" for slot_2.

    Of course it only works when there is a power up overlapping the slot.

    First I did this:

    It works fine and I can call the corresponding power-up for each slot. But I have to duplicate each power-up (event and action) for each slot. And I'm a bit lazy, so I thought that I could reduce my code to just one function that will call the correct power-up for each slot. So I will only need to edit this for futures power-ups.

    So I did this:

    So it choose the correct power-up in the function but unfortunately, it only choose the power-up overlapping the slot_1. It doesn't consider the slot ID number. I tried many different possibilities but it still doesn't work.

    So if anyone has a solution about this, it will really be helpful!!

    Thanks!

  • The conditions in the function should be pu_name = instead of PowerUp.PU_Name =

    pu_name is the parameter of the function

  • Thanks but even if I change this my result is the same

    Whenever I use the "Y" or the "B" button it always call the power-up overlapping the first slot.

    I also use a cooldown as you can see. When the power-up is called it put the cooldown boolean to true and make the power-up sprite opacity to 50%, so I can see if the function work. It should work for only a power-up at once but actually both power-up's opacity turn to 50%. That's mean it doesn't make a difference between the power-up on Slot_1 and the power-up on Slot_2.

  • Make sure you have 'copy picked' selected on the function to retain the picked instance of PU_act_slots

  • Ok thanks lionz, with the 'copy picked' selected it's a bit better: Now I can see that the cooldown effect is applied on the correct power-up object.

    But it still use the action of the power-up on the first slot for both. That's really strange because now it should works.

    Even if I inverse the event, like "if Power-up is overlapping PU_act_Slots", the result doesn't change anything…

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can add logging using the Browser object btw, I find that helpful to see if what I'm expecting to be triggered or picked is correct.

    So this sounds like when you press B it is sending through the name of the powerup overlapping slot 1 instead of slot 2. Sometimes the order in conditions matters, try moving Slot_ID= to the top of the condition above 'powerup is overlapping slot' to see if it makes a difference.

    If that doesn't work there are other possibilities like both powerups have the same name even though the animations are different. That's why the Browser logging I mentioned is good, you can see what powerup.UID is picked, or what parameter is actually passed through the function, you can log these things.

  • Sometimes the order in conditions matters, try moving Slot_ID= to the top of the condition above 'powerup is overlapping slot' to see if it makes a difference.

    That's was that! Thanks again for your help lionz!!

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