Kids Counting Game - How to Increment
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Kids Counting Game - How to Increment
I gave myself a little application to get going with Live Code by making a little counting game.
My thought was to use 7 segment pictures and adjust which one is showing on top of the stack (no pun intended). So I created my own .png files each having a digit active, and I created a simple Main Stack with add one and subtract one buttons along with an image area where the digit will be displayed. Now am I not sure what to do to cycle through digits.
Appreciate any help. Not sure how to attach my stack here so I uploaded a screenshot.
My thought was to use 7 segment pictures and adjust which one is showing on top of the stack (no pun intended). So I created my own .png files each having a digit active, and I created a simple Main Stack with add one and subtract one buttons along with an image area where the digit will be displayed. Now am I not sure what to do to cycle through digits.
Appreciate any help. Not sure how to attach my stack here so I uploaded a screenshot.
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Kids Counting Game - How to Increment
There's probably 100 ways to do this with LiveCode, here's one:
This script assumes that you have 10 images named 0.png through 9.png, and that only one of these images is visible.
Add 1 button:
Subtract 1 button
That should get you started anyway.
--Sefro
This script assumes that you have 10 images named 0.png through 9.png, and that only one of these images is visible.
Add 1 button:
Code: Select all
on mouseUp
repeat with x = 0 to 9
if the visible of img (x&".png") is true then
hide img (x&".png")
if x = 9 then
set the visible of img "0.png" to true
else
put x+1into pIMG
set the visible of img (pIMG&".png") to true
exit repeat
end if
end if
end repeat
end mouseUp
Code: Select all
on mouseUp
repeat with x = 0 to 9
if the visible of img (x&".png") is true then
hide img (x&".png")
if x = 9 then
set the visible of img "0.png" to true
else
put x+1into pIMG
set the visible of img (pIMG&".png") to true
exit repeat
end if
end if
end repeat
end mouseUp
That should get you started anyway.
--Sefro
Re: Kids Counting Game - How to Increment
Great - thank you.
I was able to edit the code for the buttons. But I don't see where all the *.png files go - all I have it an image area pointing to 0.png.
I was able to edit the code for the buttons. But I don't see where all the *.png files go - all I have it an image area pointing to 0.png.
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Kids Counting Game - How to Increment
I should have mentioned, those scripts also assumed that your images had been imported. These scripts below will work for referenced images, they assume that your stack file is in the same directory as your image files. Still named 0.png through 9.png. The image area in these scripts is named "number"
Add one button:
Subtract One Button:
--Sefro
EDIT: here's my test stack, just put it in the same folder as your images 0.png through 9.png
Add one button:
Code: Select all
on mouseUp
repeat with x = 0 to 9
put x+1 into pIMG
put "./"&pimg&".png" into pVar
if the filename of img "number" is ("./"&x&".png") then
if x is 9 then
set the filename of img "number" to "./0.png"
else
put x+1 into tNum
put "./"&tNum&".png" into pVar
set the filename of img "number" to pVar
exit repeat
end if
end if
end repeat
end mouseUp
Subtract One Button:
Code: Select all
on mouseUp
repeat with x = 0 to 9
put x-1 into pIMG
put "./"&pimg&".png" into pVar
if the filename of img "number" is ("./"&x&".png") then
if x is 0 then
set the filename of img "number" to "./9.png"
exit repeat
else
put x-1 into tNum
put "./"&tNum&".png" into pVar
set the filename of img "number" to pVar
exit repeat
end if
end if
end repeat
end mouseUp
--Sefro
EDIT: here's my test stack, just put it in the same folder as your images 0.png through 9.png
Re: Kids Counting Game - How to Increment
Thank you this works well.
I was able to add a reset button based on your code by adding "set the filename of img "number" to "./0.png" which brought the count back to zero, but I was trying to understand how I could ensure the count was also reset when the program first started. I tried to add it at Main Stack or Card level not sure which one but nothing worked. I am guessing that I don't know the language and options well enough to implement. What is the best way to understand the programming environment (for free) - I did see a way to use the find in docs which brings up the LiveCode Dictionary but the practical use seems lacking.
Also, I want to add a tens place to the count so from 00 to 99. I am thinking that I would add another set of .png files ...
I was able to add a reset button based on your code by adding "set the filename of img "number" to "./0.png" which brought the count back to zero, but I was trying to understand how I could ensure the count was also reset when the program first started. I tried to add it at Main Stack or Card level not sure which one but nothing worked. I am guessing that I don't know the language and options well enough to implement. What is the best way to understand the programming environment (for free) - I did see a way to use the find in docs which brings up the LiveCode Dictionary but the practical use seems lacking.
Also, I want to add a tens place to the count so from 00 to 99. I am thinking that I would add another set of .png files ...
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Kids Counting Game - How to Increment
I highly recommend you go through these stacks in order, it should get you up to speed in no time:
http://www.hyperactivesw.com/revscriptc ... ences.html
There's also:
http://livecodesupersite.com/tutorials.html
Which has many of the tutorials from the main LiveCode site, just laid out differently.
As far as having these image reset when the stack is first started, you could set the filename to "./0.png" in a "preopenstack" handler in your stack script.
--Sefro
http://www.hyperactivesw.com/revscriptc ... ences.html
There's also:
http://livecodesupersite.com/tutorials.html
Which has many of the tutorials from the main LiveCode site, just laid out differently.
As far as having these image reset when the stack is first started, you could set the filename to "./0.png" in a "preopenstack" handler in your stack script.
--Sefro
Re: Kids Counting Game - How to Increment
And you can even leave out the ./ path stuff
...
## put "./"&pimg&".png" into pVar
put pimg & ".png" into pVar
...
...
## put "./"&pimg&".png" into pVar
put pimg & ".png" into pVar
...
Re: Kids Counting Game - How to Increment
Sefro,
You been a great resource for getting me going thanks a million the "preopenstack" handler worked like a charm.
I will definitely study the links you sent.
I was even able to set a stand alone app as long as I made sure the .png files were copied.
You been a great resource for getting me going thanks a million the "preopenstack" handler worked like a charm.
I will definitely study the links you sent.
I was even able to set a stand alone app as long as I made sure the .png files were copied.