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!
hello
so i basically have a game where you gain money (yes thats gross but you dont need to know more)
to gain money, you just need to wait. ive made an object that when you press it, you gain 1 coin every second, by doing:
on mouseUp
repeat x = 10 //this number is only to test
wait 1 sec
add 1 to aMoney
put aMoney into field "moneyField"
end repeat
end mouseUp
(this code is working, but stopping at 10)
but this needs to repeat indefinitely, and you need to do other things at the same time, but the problem is that if you run a repeat, you cant press buttons or do anything. is there another way to add money regularly without using repeat? thanks
kelyan
...
repeat with X = 1 to 10
## or just: repeat 10
...
I wonder why LC did not complain with your syntax!?
Please provide a bit more info:
1. Does the user need to keep the mouse pressed (= down) to get the money every one second?
2. Or click once and then gain money every second?
If 1. then you should use SEND and not repeat!
Put this into the script of your "money giving" object:
on mouseDown
## If you want to give money immedaitely:
add 1 to fld "moneyfield"
send "give_me_your_money" to me in 1 secs
end mouseDown
command give_me_your_money
## Mouse is not DOWN anymore!
if the mouse = "up" then
exit to top
end if
## Mouse is still DOWN.
## We can add something directly to a field, as long as the field contains a number!
add 1 to fld "moneyfield"
send "give_me_your_money" to me in 1 secs
end give_me_your_money
I, too, am struggling with managing a repeat loop and checking for additional input.
Specifically, I have a text field which I want to scroll (as in a teleprompter). The use clicks the "start scroll" button which simply scrolls the field. That bit I can cope with!
However, I want to be able to increase/decrease the scroll speed using the arrow buttons (the arrow buttons enable me to use a remote control using designed for Keynote/Powerpoint)
Is is feasible to check the status of the arrow keys from within a loop?
More generally, is there a good tutorial on how to "do things" from within a repeating loop?
Thanks,
Tim
hello klaus!
its the option 2. the player presses a button, waits 1 sec and earns 1 coin, waits 1 sec, earns 1 coin ect... i still didnt found my answer, ill maybe modify my game or something. thanks!
snowfun wrote:
However, I want to be able to increase/decrease the scroll speed using the arrow buttons (the arrow buttons enable me to use a remote control using designed for Keynote/Powerpoint)
More generally, is there a good tutorial on how to "do things" from within a repeating loop?
Hi Tim,
I have no idea if any tutorials on this matter,
but one way to learn is to read some code from LiveCode team.
From the IDE, select menu "About LiveCode" and you'll see a scrolling text
Then, look at the script and you'll know one way to do it.
The stack is named "revAbout.rev", the script is in field "Credits".
Hope this helps and good luck,
Thierry
! SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
kelyanok wrote: Thu Apr 02, 2020 9:37 am
hello klaus!
its the option 2. the player presses a button, waits 1 sec and earns 1 coin, waits 1 sec, earns 1 coin ect... i still didnt found my answer, ill maybe modify my game or something. thanks!
oh, easy money!
OK, in that case just omit the mouse = up part, but memorize the ID of the SEND message, so you can CANCEL it when the stack closes!
global give_money_id
on mouseDown
## If you want to give money immedaitely:
add 1 to fld "moneyfield"
send "give_me_your_money" to me in 1 secs
end mouseDown
command give_me_your_money
## Mouse is still DOWN.
## We can add something directly to a field, as long as the field contains a number!
add 1 to fld "moneyfield"
send "give_me_your_money" to me in 1 secs
put the result into give_money_id
end give_me_your_money
on mouseup
put empty into fld "fDev2"
repeat with i = 1 to 100
if the optionkey is down then exit repeat
put "***" & the ticks into tDev
put tDev into fld "fDev1"
wait 10 milliseconds with messages
put the keysdown into tKD
if tKD <> empty then -- exit repeat works
answer (tKD = empty) -- answer dialog doesn't appear
put tKD into fld "fDev2" -- fld "fDev2" is empty
exit repeat
else
put "tKDEmpty" & the ticks into fld "fDev2"
end if
end repeat
end mouseup
Curiously I can stop a loop with arrowkey (works with others) but the keysdown seems empty. If that is the case, why loop is stopped
Edit: wait 10 milliseconds instead 1000 milliseconds is better
Thanks for your lights
Best regards
Jean-Marc
Last edited by jmburnod on Thu Apr 02, 2020 4:17 pm, edited 1 time in total.
The following slightly edited version of your script seems to "work". It isn't very smooth and I guess there are areas to improve but it does do the basics (ie changes the speed of scrolling using the up and down arrow keys). One issue is that I need to cancel the effect of long key presses which have a cumulative (and undesirable) effect.
on mouseup
put 1 into vIncrement
put vIncrement into fld "ftest"
put "" into fld "fkeydown"
repeat
if the optionkey is down then exit repeat
set the vscroll of fld "fscrolltext" to the vscroll of fld "fscrolltext" + vIncrement --this can possibly be improved
wait 10 milliseconds with messages --still testing the effect of the delay
put the keysdown into tKD
if tKD <> empty then put tKD into fld "fkeydown" --check the key pressed
if tKD = 65362 then
put vIncrement + 1 into vIncrement
put vIncrement into fld "ftest" --works
end if
if tKD = 65364 then
put vIncrement - 1 into vIncrement
put vIncrement into fld "ftest" --works
end if
end repeat
end mouseup
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..