TOUR
PRICING
HELP
Stencylpedia
Blocks Guide
Sample Games
Developer Center
FORUMS
CHAT
#MADEINSTENCYL
EDUCATION
SIGN IN
×
Welcome back!
Username or E-mail
Password
(
Forgot?
)
C
OMMUNITY
Home
Issue Tracker
Inbox [0]
New Posts
New Replies
Search
Stencyl Community
→
Stencyl
→
Ask a Question
→
buying units from town center?
Pages:
1
buying units from town center?
poehyrulian
Posts: 78
December 06, 2016, 12:21:17 pm
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
CmdrWhitey13
Posts: 504
December 06, 2016, 12:47:20 pm
Take a look at this video. Even though its in java, it still explains what is going on.
https://youtu.be/e3-TZ7TfJjA?t=13m33s
Possible extra boolean variable maybe required.
Hope it helps.
domagojbulat
Posts: 207
December 06, 2016, 01:03:00 pm
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"?
Castle Woodwarf 2
Castle Woodwarf
Earthlings
Quarrel Hill
squeeb
Posts: 1617
December 06, 2016, 03:25:39 pm
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
Like my page
https://www.facebook.com/FirstPassProductions/
Check out my apps and games, more to come
https://play.google.com/store/apps/developer?id=First+Pass+Productions&hl=en
thechaosengine
Posts: 329
December 07, 2016, 03:23:25 am
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
poehyrulian
Posts: 78
December 07, 2016, 01:18:57 pm
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.
KramerGames
Posts: 405
December 08, 2016, 05:38:07 am
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)
Pages:
1