Remembering player names, timers and losing lives

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
Noytal
Posts: 9
Joined: Sun Apr 10, 2016 6:10 pm

Remembering player names, timers and losing lives

Post by Noytal » Wed May 25, 2016 9:41 am

I'm making a matchstick puzzle game for an IT course, and I'm a bit stuck with regards to the elements mentioned in the title.

The game is a fixed grid, with buttons that use matchstick icons that the player clicks and drags to make a specific shape. I need to implement a timer which counts down from 60, and upon reaching zero will end the game.
What I have for that so far is a card that open on a screen-sized button saying "click to start":

Code: Select all

global sFlag
global lives

on mouseUp
   show field "displayTimer"
   put 60 into field "displayTimer"
   put true into sFlag
   send "updateTimer" to card "puzzle #1"
   put 3 into lives
On the card I have:

Code: Select all

global sFlag    

on updateTimer
   subtract 1 from field "displayTimer"
   if field "displayTimer" = 0 then 
      put false into sFlag
      answer "Game Over"
   end if
   if sFlag is true then 
      send "updateTimer" to me in 1 second
   end if
end updateTimer 
The problem here is that after clicking "Submit" (which checks if each match is true or false depending on which grid lines each of them intersects with) I get an execution error saying "Chunk: no such object" at "subtract 1 from field "displayTimer". I have tried putting some code in the Submit button to stop the timer, but it just doesn't work:

Code: Select all

   if V8 and  V10 and H5 and H10 and H12 then
      put false into sFlag
   end if

As well as this, I need to remember a player's name. On my "introduction" screen, I have a little avatar who pretends to be Professor Oak and asks for your name. I have a simple "ask "What is your name?"", but I need to have a text field that uses that name. Like "So, Noytal is it?". How could I do this?

And last request, if the player submits a wrong answer three times, they lose. I have a field for displaying lives, a variable "lives" and the opening button puts 3 into lives. When the user presses Submit and is wrong, I need to change it to put 2 into lives, then 1 into lives, then go to a game over card. How do I do this?

Thanks, sorry if my request is vague, and I can provide more details if you need.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Remembering player names, timers and losing lives

Post by dunbarx » Wed May 25, 2016 12:25 pm

Hi.

Are we sure we are on the right card? If so, the "submit" button does not throw an error, but the card script does? That is the first question I have, before going anywhere else.

Craig Newman.

Noytal
Posts: 9
Joined: Sun Apr 10, 2016 6:10 pm

Re: Remembering player names, timers and losing lives

Post by Noytal » Sun Jun 05, 2016 12:49 pm

Sorry, forgot I asked this. I removed the "correct" card, and just made the submit button play the "correct" animation on the puzzle card, so it works a bit better now.

I still am really stumped though. On my little intro card I have an

Code: Select all

ask "What is your name?"
line, but I need a way to put the answer into another ask,

Code: Select all

ask "*player's name*, is that correct?"
. How do I do this?

And literally the only other thing I need to do is make it so when the player clicks "submit" and gets it wrong three times, it plays a "you lose" animation. Right now the only thing I can think of for that is copying the entire contents of the card to make four identical cards, and making the submit button go to the next card each time until it is the fourth card, at which point it shows the "you lose" animation. Maybe have a fake lives "counter" or something.

Noytal
Posts: 9
Joined: Sun Apr 10, 2016 6:10 pm

Re: Remembering player names, timers and losing lives

Post by Noytal » Sun Jun 05, 2016 1:28 pm

Ok, I got the ask/ answer bit sorted.

Code: Select all

global tName
on mouseUp
   // Go to next text box
   Hide Field "Text 2"
   Hide button "Button 2"
   show btn "button 3"
   ask "What is your name?" put it into tName 
end mouseUp

Code: Select all

global tName
on mouseUp
   // Go to next text box
   answer tName & ", is that correct?" with "No" or "Yes"
   show field "Text 7"
   Hide button "button 3"
   show btn "button 4"
end mouseU

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Remembering player names, timers and losing lives

Post by Klaus » Sun Jun 05, 2016 5:16 pm

Noytal wrote:Ok, I got the ask/ answer bit sorted...

Code: Select all

...
  Hide Field "Text 2"
  Hide button "Button 2"
  show btn "button 3"
...
Great, now you can start to give your objects meaningful names! :D

Post Reply