Kids Counting Game - How to Increment

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

Post Reply
bmalkows
Posts: 12
Joined: Fri Nov 28, 2014 6:47 am

Kids Counting Game - How to Increment

Post by bmalkows » Sat Dec 06, 2014 6:52 pm

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.
Attachments
count.jpg

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Kids Counting Game - How to Increment

Post by sefrojones » Sat Dec 06, 2014 7:44 pm

There's probably 100 ways to do this with LiveCode, 8) 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:

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
Subtract 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

That should get you started anyway. :)

--Sefro

bmalkows
Posts: 12
Joined: Fri Nov 28, 2014 6:47 am

Re: Kids Counting Game - How to Increment

Post by bmalkows » Sat Dec 06, 2014 9:33 pm

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.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Kids Counting Game - How to Increment

Post by sefrojones » Sat Dec 06, 2014 10:31 pm

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:

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
numbers_test.livecode.zip
(814 Bytes) Downloaded 202 times

bmalkows
Posts: 12
Joined: Fri Nov 28, 2014 6:47 am

Re: Kids Counting Game - How to Increment

Post by bmalkows » Thu Dec 11, 2014 1:20 pm

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 ...

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Kids Counting Game - How to Increment

Post by sefrojones » Thu Dec 11, 2014 5:53 pm

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

Klaus
Posts: 13864
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Kids Counting Game - How to Increment

Post by Klaus » Thu Dec 11, 2014 6:31 pm

And you can even leave out the ./ path stuff :D
...
## put "./"&pimg&".png" into pVar
put pimg & ".png" into pVar
...

bmalkows
Posts: 12
Joined: Fri Nov 28, 2014 6:47 am

Re: Kids Counting Game - How to Increment

Post by bmalkows » Thu Dec 11, 2014 7:09 pm

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.
Attachments
Windows App.jpg

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”