Forum rules - please read before posting.

Puzzle: Swap colors on click.

Hey guys,

I'm new to AC, so far I found it awesome! I can code but with AC it removed me hours of work. Im doing a simple game for my son and I have a problem.

I want to make a puzzle, simply you have 4 buttons (Objects) when you click on them they change the color (Up to 3 colors each) if all of them are the same color then the puzzle is over.

My issue is, I want to swap the material of each button when it's clicked however I can't do that. Clicking one I can change the material, there is no issue. But how can I make that each time I press it changes to a different one? I tried doing a sequence and it auto runs, then I tried with a popup switch but doesnt work.
In short my main issue seems to be, how can I run the action only when you pressed again in the same object? Not sure if im making any sense and I can't seem to post pictures.

Thx





Comments

  • edited September 2017
    Hello!

    So the puzzle is four squares that can change three colors and one they are all the same,the puzzle it is solved (just clarifying).

    This is what I would do -

    create 3 integer variables - one for each color, leave them at 0

    Hypothetically lets say the colors are blue, red, and yellow and change color in that order.

    When the puzzle starts off the integer variable for each color should match with how many buttons are of that color. If at the start of the puzzle there is one blue button, one red button, and two yellow buttons, the integers would be Blue = 1, Red = 1, Yellow = 2.

    For each button interaction, make three use interactions and disable the last two. The first one will be for color that button will be first (blue), the second interaction will be for that button when its pressed once (red), and the last one is for when the button is pressed a second time (yellow). During each interaction at some point it should change that buttons hotspot interaction to the color it will be turning next, so if the button is blue first the button interaction for blue should change the hotspots interaction to red. Do this for each button.

    In order for the game to keep track of how many buttons are of each color, the integer variables will have to change every time a button is pressed. So when the blue button is pressed it will be come red and the variables will now be Blue = 0, Red = 2, Yellow = 2. To do this the interaction should add -1 to Blue and add 1 to Red. Then keep doing this for ever interaction between each button, changing which variable will have 1 added or subtracted depending on the interaction.

    Finally, at the end of each interaction all three variables need to be checked to see if they equal 4 because if one of them equals four that means that all four buttons are the same color. So, if none of the buttons equal four then the game should do nothing, but if one of them does equal four than the puzzle should end.

    I hope this helps (and makes sense). If you have any questions please feel free to ask.
    I'm not 100% sure this will work sense I've never made a puzzle specifically like this before, but at the very least it is a possible working solution.
  • Welcome to the community, @rubendarioramirez.  Glad to hear of your target audience :)

    I'm not too sure I follow completely, I'm afraid - does clicking one object change all, or just the one?  Is it changed randomly, or in a set sequence?  Images can't be hosted on the site directly, but you can post to any image-sharing site such as imgur.com and link to them instead.
  • Hey! Thanks for of you for the fast response.
    Let me try to explain it better and Im going to make it a smaller problem since I know how to solve the rest.

    You have 1 Cube, when you press on this cube, I want it to change the color (Switching material). 
    So Click - Object goes Red -> Click -> Object goes Yellow --> Click --> Object goes Green --> Click --> Object comes back to Red.

    AlphaPsychO anyway) but I can't make that changing material work. Because I tried using a PopUpSwitch or a Sequence and in both cases in the first CLICK the object goes straight to the last color (In this case green) because looks like it doesnt wait for me to click again. So I tried to use Input check Click or Touch, but doesnt seem to work at least for me.

    Thanks and I hope is more clear! I dont post a picture because I deleted the solutions I was trying.





  • BTW, Yes AlphaPsycho I think your solution can work, but correct me if im wrong, but doing 3 interactions per cube it's not a bit too much? SHouldn't be a way to make it all in the same interaction? 
  • The Input: Check Action on a loop is not recommended.  If you want to detect generic input, it's better to instead use Active Inputs - see Section 2.6 of the Manual.  However, using a regular Hotspot Interaction for handling clicks to the cube should be enough.

    Using a sequence should be the correct approach.  Were you linking it to a Variable?  It shouldn't be the case that the Interaction is run multiple times with the same click, unless the Actions have been wired up that way.  Know that Actions can be assigned comments in the ActionList Editor
    window, which can be printed in the Console - see Section 5.2.3 - which may be useful for you when debugging.

    Is the problem more to do with the material-changing?  You can test the Object: Change material Action on its own by placing it in a separate Cutscene and clicking "Run" in it's Inspector at runtime.

    Once this is solved for you, know that you can extend your completed ActionList for others by turning it into a parameterised Cutscene.  ActionList parameters (see Section 5.14) work like function parameters in that they can modify Actions they are passed to - see this tutorial.
  • edited September 2017
    Something on what you said enlighten me. So I was doing everything right but one thing. When I finished one action I was wiring it up back to the sequence, so it was running all the time. Now it looks like this:

    image

    And works fine. Thanks a lot for your fast response! You plugin is by far the best asset in the store! 
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.