how do i make a toggleable button?

  • i'm creating a game like rimworld, where you can tell characters to collect certain items, like go to a tree -> destroy it -> collect wood, but i've gotten stuck on a problem, i want the script to make the character go to the tree if i press J and if i press J again, he goes back to his original point (i'm making the collect wood feature later)

    i've set this up but i'm not quite sure what's wrong with it, whenever i press the J key, it just makes the character circle around for a split second then stay still. the placeholder "wood" text to tell me if it's activated or not doesn't change either.

    if someone could correct my script that'd be nice :)

  • Hiya, I can see what the problem is, because events run top to bottom in construct, it is setting it to 1 then back to 0 in the same tick i.e. you won't see anything change. You could solve it by putting a wait or timer before setting the variable. Another way would be to actually make a toggleable variable so have wood.checked as a boolean, on J pressed toggle the boolean, then have events if true or false do such a thing instead of 0/1. That would mean a single press of J toggles the boolean and avoids the setting back and forth problems.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hiya, I can see what the problem is, because events run top to bottom in construct, it is setting it to 1 then back to 0 in the same tick i.e. you won't see anything change. You could solve it by putting a wait or timer before setting the variable. Another way would be to actually make a toggleable variable so have wood.checked as a boolean, on J pressed toggle the boolean, then have events if true or false do such a thing instead of 0/1. That would mean a single press of J toggles the boolean and avoids the setting back and forth problems.

    hi, i tried this, and changed it to a boolean, now when i press J, the animation updates and changes the placeholder "wood" text to green to tell me it's working, but now the character doesn't move towards the tree at all, what's the problem? i have a feeling i did the "is checked" thing wrong or used the wrong command but i can't find another boolean related condition

  • Pathfinding behaviour doesn't work like that. You will need to add a trigger once condition on the left so it doesnt keep finding a path. The find path action can remain. Then you need a new event, redcultist on path found > move along path. You can find more about that behaviour in the manual.

  • Pathfinding behaviour doesn't work like that. You will need to add a trigger once condition on the left so it doesnt keep finding a path. The find path action can remain. Then you need a new event, redcultist on path found > move along path. You can find more about that behaviour in the manual.

    ah, thanks! i get it now and it's working, how would i make it so he constantly goes from tree to tree until i turn the boolean off? thanks for all your help :)

  • Well you would have on arrived > find path to tree, but you will need something to decide which trees he is picking. If he goes to the closest one each time you can do pick nearest tree to player > find path to tree. With that though he will always pick the one he is standing on, so you will need to take the trees he has arrived at out of the route, so when he arrives at a tree you could toggle a boolean on the tree to true, which would mean find pick nearest tree to player where tree.bool=false > find path to tree.

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