Book Image

LiveCode Mobile Development Cookbook

By : Dr. Edward Lavieri
Book Image

LiveCode Mobile Development Cookbook

By: Dr. Edward Lavieri

Overview of this book

Table of Contents (17 chapters)
LiveCode Mobile Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using a loop to count


There are numerous reasons why you might want to implement a counter in a mobile app. You might want to count the number of items on a screen (that is, cold pieces in a game), the number of players using your app simultaneously, and so on. One of the easiest methods of counting is to use a loop. This recipe shows you how to easily implement a loop.

How to do it...

Use the following steps to instantiate a loop that counts:

  1. Create a new main stack.

  2. Rename the stack's default card to MainScreen.

  3. Drag a label field to the card and name it counterDisplay.

  4. Drag five checkboxes to the card and place them anywhere. Change the names to 1, 2, 3, 4, and 5.

  5. Drag a button to the card and name it Loop to Count.

  6. Add the following code to the Loop to Count button:

    on mouseUp
      local tButtonNumber
       
      put the number of buttons on this \
      card into tButtonNumber
      if tButtonNumber > 0 then
        repeat with tLoop = 1 to tButtonNumber
          set the label of btn value(tLoop) to \
          "Changed...