[Help]Creating a clicker game

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

AgentItay
Posts: 60
Joined: Mon Aug 24, 2015 8:54 pm
Location: Israel

Re: [Help]Creating a clicker game

Post by AgentItay » Wed Aug 26, 2015 11:23 pm

dunbarx wrote:
I also didn't understand what option key is.
How did you stop the handler? The "Alt" key is the Windows version.

So my first question stands. How did you stop the handler? It will run forever, unless you have a means of exiting. I had:

Code: Select all

 if the optionKey is down then exit addDough
I was trying to lead you to something similar, like:

Code: Select all

if the mouseLoc is within the rect of button "yourStopButton" and the mouse is down...

or

if the stopFlag of this stack is "Stop"...

or

if the hilite of button "yourStopButton" is "true" then...
"stopFlag" would be a custom property (do you know what those are?) set by that button. The hilite of your stop button could be set when you click it. All these and more are possible, and the choice is yours.The point is that the looping handler tests some condition or property in order to know whether to continue or exit.

Write back. There may be much to talk about.

Craig
I appreciate your help, Craig
I do not know what custom properties are. And I don't really understand how to set the stopFlag, and just to cleartify, the stop flag is basically the reset button, am I right?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: [Help]Creating a clicker game

Post by dunbarx » Wed Aug 26, 2015 11:40 pm

OK. Let's slow down.

I insist that you tell me how you stopped the first handler I wrote. I gave you the ability to press the option (or alt) key.

Once we know that, you can answer the following questions:

Do you see that some exiting method will be required, because that handler will not stop by itself? Do you see that it will run forever? Is it in fact still running? :wink:

Craig

AgentItay
Posts: 60
Joined: Mon Aug 24, 2015 8:54 pm
Location: Israel

Re: [Help]Creating a clicker game

Post by AgentItay » Wed Aug 26, 2015 11:57 pm

dunbarx wrote:OK. Let's slow down.

I insist that you tell me how you stopped the first handler I wrote. I gave you the ability to press the option (or alt) key.

Once we know that, you can answer the following questions:

Do you see that some exiting method will be required, because that handler will not stop by itself? Do you see that it will run forever? Is it in fact still running? :wink:

Craig
I stopped it by either closing the app (which I don't want it to happen) and by pressing the alt key.
And yes, I understand but I don't seem to find how to do that.
What I tried to do is sending a stop command once the reset progress button is clicked, but it won't work, when I try to do:
on stopAddingPoints
exit addPoints
end stopAddingPoints

But it gives me a syntax error.
And yes, I know the answers for your questions.
Thanks for your help.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: [Help]Creating a clicker game

Post by dunbarx » Thu Aug 27, 2015 4:06 am

Hmmm.

Your thinking is good, but your syntax is awful. You cannot just write things. LC is likely not to understand, even if no error is thrown

So let's say you want to stop the handler when you click a "stop" button. If you recall, the original way to exit was to press the "alt" key. When each pass through the handler began, the condition of that key was examined, and if it was down, the handler exited.

We can use any condition at all to do the same thing. So to start (and this may not be the best way), make another button named "stopHandler". In that button script:

Code: Select all

on mouseUp
   if the label of me = "run" then set the label of me to "Halt"
   else set the label of me to "Run"
end mouseUp
Now in the original handler change the "optionKey" line to this:

Code: Select all

if the label of btn "stopHandler" = "halt" then exit addDough
Do you see? Can you think of five other ways to do the same thing? Oh yes, why won't the "addDough" handler work anymore?


Craig

AgentItay
Posts: 60
Joined: Mon Aug 24, 2015 8:54 pm
Location: Israel

Re: [Help]Creating a clicker game

Post by AgentItay » Thu Aug 27, 2015 8:48 am

Maybe a button that will emulate the option key?
Maybe a button that will ask the user if he's sure that he wants to reset his progress and if it is yes then it will stop the addDough script?
For example

Code: Select all

on mouseUp
answer "Are you sure?" with "Yes" or "No"
if it is "Yes"
then
// No idea what to put here :/.
end if
end mouseUp
Other than that I don't seem to come up with any other ideas.
And the addDough handler works for me perfectly, as long as the label of the button is set to Run (but then I have to re-purchase it).
But for some reason, when the user exits the stack, it still stops adding points to the points field.
Thanks for your help.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: [Help]Creating a clicker game

Post by dunbarx » Thu Aug 27, 2015 1:56 pm

On a new card make two buttons and one field. Name one button "StartProcess", and In its script:

Code: Select all

on mouseUp
   addDough
end mouseUp

on mouseEnter
       set the label of btn "stopHandler" to "Halt"
end mouseEnter

on addDough
  if the label of btn "stopHandler" = "halted" then exit addDough
   add 0.2 to fld 1
   send "addDough" to me in 12 ticks --0,2 seconds
end addDough
For the other button, name it "stopHandler", and in its script:

Code: Select all

on mouseUp
   if the label of me = "Halt" then set the label of me to "Halted"
   else set the label of me to "Halt"
end mouseUp
I do not know what you mean when you say:
But for some reason, when the user exits the stack, it still stops adding points to the points field.
The incrementing of the field will continue whether or not the stack is in front, or whether LiveCode itself is in front. Nothing will stop that process unless you click on the "Halt" button, or do something much more drastic. Is this true for you?

Your homework is to examine and step through these handlers.

Craig

AgentItay
Posts: 60
Joined: Mon Aug 24, 2015 8:54 pm
Location: Israel

Re: [Help]Creating a clicker game

Post by AgentItay » Thu Aug 27, 2015 4:09 pm

Thanks for your help Craig.
What you said is not what is happening to me, whenever I leave LiveCode or the mainstack itself, it stops the incrementing of the field.

And the script you gave me for the stop button is great, but it's not what I need, I am using an answer code

Code: Select all

answer "Are you sure you want to restart" with "Yes" or "No"
if it is yes
// I want the stopHandler script to go here somehow, but without changing the label of the button, just that it'll stop it when the answer for the question is yes.
end if
I want the stopHandler script to go here somehow, but without changing the label of the button, just that it'll stop it when the answer for the question is yes.
And I pretty much understand those handlers :D.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: [Help]Creating a clicker game

Post by dunbarx » Thu Aug 27, 2015 4:26 pm

Make another button. Put this into its script:

Code: Select all

on mouseUp
   answer "Stop?" with "Stop" or "Cancel"
   if it is "stop" then 
      repeat for each line tLine in the pendingMessages
         cancel item 1 of tLine
      end repeat
   end if
end mouseUp
Now I just wrote this quickly. It very well may be that you do not want to cancel all pendingMessages, but only the one generated by the "send" command in your handler. I leave it to you to look up the "send" command in the dictionary, and rewrite this so that only the ID of the pendingMessage you generated is cancelled.

Craig

Edit:

I would normally do this by setting a custom property. Let me know when you want to talk about those. Canceling the pendingMessage is probably more correct, but I like custom properties.

AgentItay
Posts: 60
Joined: Mon Aug 24, 2015 8:54 pm
Location: Israel

Re: [Help]Creating a clicker game

Post by AgentItay » Thu Aug 27, 2015 6:12 pm

Thanks :)
The code you gave me is great.
I tried saving it as an exe and check if something changes, but not only that it stops adding points, it doesn't even save the amount of points that exsited before closing the application.
I also did make a Save button with the line save this stack, but it doesn't work.
Also, I can talk about custom properties whenever you can :)

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

Re: [Help]Creating a clicker game

Post by sefrojones » Thu Aug 27, 2015 6:20 pm

You should check out these stacks, and go through them thoroughly:

http://www.hyperactivesw.com/revscriptc ... ences.html


--Sefro

HInt: Standalones can't save themselves.

edit: Also check out these course materials as well: http://livecode.byu.edu/indexgeneric.php

edit 2: This site is geared specifically toward games: https://sites.google.com/a/pgcps.org/livecode/
Last edited by sefrojones on Thu Aug 27, 2015 6:29 pm, edited 1 time in total.

AgentItay
Posts: 60
Joined: Mon Aug 24, 2015 8:54 pm
Location: Israel

Re: [Help]Creating a clicker game

Post by AgentItay » Thu Aug 27, 2015 6:29 pm

Is it impossible? Then how can I code games that requires save files?

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

Re: [Help]Creating a clicker game

Post by sefrojones » Thu Aug 27, 2015 6:30 pm

It is impossible for a standalone to save itself due to the way modern file systems work, it is not impossible to save data in another form, such as a stack or text file, etc.

AgentItay
Posts: 60
Joined: Mon Aug 24, 2015 8:54 pm
Location: Israel

Re: [Help]Creating a clicker game

Post by AgentItay » Thu Aug 27, 2015 6:32 pm

sefrojones wrote:It is impossible for a standalone to save itself due to the way modern file systems work, it is not impossible to save data in another form, such as a stack or text file, etc.
And how do I do that? Is it included in the tutorials you sent me? Which one of them?

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

Re: [Help]Creating a clicker game

Post by sefrojones » Thu Aug 27, 2015 6:36 pm

I highly recommend you go through all of the scripting conference stacks in order, as well as the BYU course. In the meantime, these tutorials should get you started on basic file I/O :

http://lessons.runrev.com/m/4603/l/4409 ... ng-to-file

and mobile specific:

http://lessons.runrev.com/m/4069/l/1522 ... ile-device


--sefro

AgentItay
Posts: 60
Joined: Mon Aug 24, 2015 8:54 pm
Location: Israel

Re: [Help]Creating a clicker game

Post by AgentItay » Thu Aug 27, 2015 7:52 pm

Thanks Sefro, I also found another I/O lesson in runrev website but it won't work, a file won't be created.

Post Reply

Return to “Talking LiveCode”