Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Apr 02, 2020 6:44 pm
kelyanok wrote: ↑Thu Apr 02, 2020 6:25 pm
Hallo Klaus!
in my game, there is a level system. when you have 10 money, the btn levelUpFa is enabling. you click it, you loose 10 money, and you earn +1 money each second. i did it with my old code, but with yours i dont really know where to check my money ect..can you help me?
thanks
kelyan
Hm, this is a completely new situation and may require some changes in your workflow.
What did you write in your old script?
-
kelyanok
- Posts: 22
- Joined: Sun Feb 23, 2020 8:48 am
Post
by kelyanok » Thu Apr 02, 2020 6:49 pm
let me remember:
Code: Select all
...
if aMoney > 9
then
enable btn "levelUp1"
end if
...
something like that. i tried to put this code after the "add 1 to aMoney" but it enabled the btn at like 1 money..
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Apr 02, 2020 7:06 pm
Hm, let me see...
Maybe remove the givemoney handler from the button and put it into the stack script and let it accept one parameter,
so you can call it from everywhere.
Code: Select all
global give_money_id
## So we can pass any number (also negative numbers like -10)
command give_me_your_money the_amount_of_money
## If we do not pass a number, the handler will use 1 (for your periodic money adding):
if the_amount_of_money = EMPTY then
put 1 into the_amount_of_money
end if
## Mouse is still DOWN.
## We can add something directly to a field, as long as the field contains a number!
add the_amount_of_money to fld "moneyfield"
## LC will first examine the values in parens, so we can do this "Boolean" trick :-)
set the enabled of btn "levelUp1" to (fld "moneyfield" > 9)
## We will SEND this handler only if we add 1 = periodic adding of money!
## This way we can use it to just add or subtract any value <> 1 from the "moneyfield"
if the_amount_of_money <> 1 then
exit give_me_your_money
end if
send "give_me_your_money" to me in 1 secs
put the result into give_money_id
end give_me_your_money
So when clicking the button which steals you 10 "money" you can:
Code: Select all
on mouseup
give_me_your_money -10
end mosueup
Understand what I am doing here? Ask if not!
Best
Klaus
-
snowfun
- VIP Livecode Opensource Backer

- Posts: 16
- Joined: Tue May 29, 2007 7:22 am
Post
by snowfun » Thu Apr 02, 2020 7:23 pm
Hi Klaus,
Apologies if you misinterpret my post as "hijack".
The OP stated: "but the problem is that if you run a repeat, you cant press buttons or do anything." which is exactly the scenario I posted about too. I understand how the OP's question has developed into a somewhat different scenario but at the time I posted I did feel that I was discussing the same situation. Perhaps, adopting a positive and optimistic approach, it might be possible to share resources and benefit from each other's posts. Jean-Marc's assistance might be useful to the money game?
But I guess that is not the way this forum is supposed to function so, again, I apologise for upsetting you.
Best wishes,
Tim
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Apr 02, 2020 7:40 pm
Hi Tim,
I am not upset, you will notice if I am!
It is just about the clearness of this forum, sorry if I might have sounded too harsh.
Best
Klaus
-
kelyanok
- Posts: 22
- Joined: Sun Feb 23, 2020 8:48 am
Post
by kelyanok » Thu Apr 02, 2020 8:01 pm
hello Klaus
i didnt saw your answer, i did this:
Code: Select all
if aMoney > 9
then
enable btn "levelUpFa"
else
end if
so this works, but i copy paste it just after it to enable a btn when you are a 100, but didnt worked.. so: 1. is my code right? and 2. if it is not, what should i do? simply use your code?
thanks
-
kelyanok
- Posts: 22
- Joined: Sun Feb 23, 2020 8:48 am
Post
by kelyanok » Thu Apr 02, 2020 8:03 pm
oh nevermind, i misspelled something. it works.
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Apr 02, 2020 8:10 pm
Okie Dokie!
Hint: If you don't have an ELSE case, you don't need to mention it
Code: Select all
...
##if aMoney > 9
## then
## enable btn "levelUpFa"
## else
## end if
...
if aMoney > 9 then
enable btn "levelUpFa"
end if
...
-
kelyanok
- Posts: 22
- Joined: Sun Feb 23, 2020 8:48 am
Post
by kelyanok » Thu Apr 02, 2020 8:12 pm
oh ok. I'll think about it next time thanks