buying units from town center?


  • Posts: 78
Ok im on a few projects now and on one of them im having an issue buying units in my kingdom game. I have it set to where when i click buy it checks my current resources and if i have enough it takes the cost away and adds one unit of the selected type. Tye problem is that when i click the buy button it purchases the max amount of units possible instead of just one. Code reads
When buy is clicked on
If (gold cost <=gold and food cost <=food and buy = false
Set buy to true
Set villagers to villagers + 1
Do after .01 seconds
Set buy to false.

Wish i could post tye blovks but im not home right now


  • Posts: 504
Take a look at this video. Even though its in java, it still explains what is going on.

Possible extra boolean variable maybe required.
Hope it helps.


  • Posts: 207
I think there is no need for buying boolean. I tried it like this and it works, adding villagers one by one (I ommited the gold and food)
Maybe you used something other than "is pressed on self"?


  • Posts: 1617
Yes.. I'd try on released.. not pressed.. it may be executing the code the whole time someone is pressing down.. instead of one time


  • *
  • Posts: 329
Something I do sometimes in these kind of setups is, I attach the animation states of an actor to the event. So in this situation you'd get

When the mouse is pressed on self
if [current animation for self is Idle]
switch animation to pressed for self
if [gold cost <= Gold] & [food cost <= Food]
set [villagers to [villagers+1]]
do after 0.2s
switch animation to idle for self


  • Posts: 78
Thank you domogoj that solved the problem flawlessly. i feel dumb for not trying that haha. i use that boolean for attacking to keep the damage from going further than the set parameter and just assumed that it would be nescessary for purchases as well. and i would use an animation state but at this time i just have it highlighted.


  • Posts: 405
Has something changed here? It used to work fine that the codes under "when mouse is pressed on actor" are only triggered once per mouseclick, but now Im having the same problem that it is triggered multiple times and I have to stop it "manually".
Parasites United  (Idle Parasite Game)