[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

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

Re: [Help]Creating a clicker game

Post by dunbarx » Sat Aug 29, 2015 7:14 pm

And no, it only stops whenever I close the stack or/and livecode.
I am now confused. It only stops when you close the stack or quit LC? That seems like expected behavior to me. Please tell me exactly what you want it to do.

Craig

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

Re: [Help]Creating a clicker game

Post by AgentItay » Sat Aug 29, 2015 8:12 pm

That's right, but the point in those kind of games is to keep adding points everytime you open the game, therefore, I don't want it to stop.
Those kind of games are called idle games, feel free to check what they are.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: [Help]Creating a clicker game

Post by Simon » Sat Aug 29, 2015 8:21 pm

...feel free to check what they are.
That's a bit over the top. Who's designing this you or Craig?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: [Help]Creating a clicker game

Post by AgentItay » Sat Aug 29, 2015 8:32 pm

Simon wrote:
...feel free to check what they are.
That's a bit over the top. Who's designing this you or Craig?

Simon
Me, I didn't mean at any way that he'll design it for me, I just want hints, what I meant by that was that he can check what idle games are, since he doesn't seem to know that.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: [Help]Creating a clicker game

Post by Simon » Sat Aug 29, 2015 8:46 pm

The 2 links I posted were how you save data (persistence) from one run to the next.
You have to write the ending "amount" before you exit the read it back in on start.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1682
Joined: Sat Feb 28, 2009 11:49 pm

Re: [Help]Creating a clicker game

Post by sturgis » Sat Aug 29, 2015 9:18 pm

It sounds like you need to know the time of the last update before closing the app, the final amount, and any owned "factories".

At which point, the next time you open up the stack, you read in the previous balance, figure out the time since last access and do the math to update your score to the current state.

The easiest way (when the stack is shutting down) would be to store "the seconds" (and as I said above) the score, and the number of factories. Then when starting up again, get "the seconds" (aka the time it is now, in seconds) subtract "the seconds" that you stored in your file, then use that number. So, for example if you are adding score every 20 seconds and its been 20000 seconds since you played the game last, there are 1000 scoring intervals.

1000 x .2 x the number of factories owned, added to the score that you saved right before shutdown last time.

IE (scoring intervals x the score increase x factories) + previous score

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

Re: [Help]Creating a clicker game

Post by AgentItay » Sat Aug 29, 2015 9:41 pm

sturgis wrote:It sounds like you need to know the time of the last update before closing the app, the final amount, and any owned "factories".

At which point, the next time you open up the stack, you read in the previous balance, figure out the time since last access and do the math to update your score to the current state.

The easiest way (when the stack is shutting down) would be to store "the seconds" (and as I said above) the score, and the number of factories. Then when starting up again, get "the seconds" (aka the time it is now, in seconds) subtract "the seconds" that you stored in your file, then use that number. So, for example if you are adding score every 20 seconds and its been 20000 seconds since you played the game last, there are 1000 scoring intervals.

1000 x .2 x the number of factories owned, added to the score that you saved right before shutdown last time.

IE (scoring intervals x the score increase x factories) + previous score
Thanks, but I don't seem to find the seconds and the number of factories in the script, I am completely lost and don't know how to store that information.
I thought that I need to do that, but I wasn't sure, but let me guess, for it I need to learn variables?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1682
Joined: Sat Feb 28, 2009 11:49 pm

Re: [Help]Creating a clicker game

Post by sturgis » Sat Aug 29, 2015 10:06 pm

I haven't poked through the whole thread yet, but.. Do you know how to save information to a file yet?

Well first..

Look in the dictionary under "seconds"

In your message box if you: put the seconds it'll pop out a number representing the current time in seconds.

So yes, you would want to store that number.

A very simple way to store info is in a regular old text file.

So say you wanted to store the seconds, the score, and the number of factories for later use you can use the keyword "URL" to put stuff into a file.

So far we've discussed 3 things you might need to save. To put them into a file you could do this: put the seconds & comma & field "score" & comma & field "myFactories" into URL "file:mysavefile.dat"
In this example field "score" would have your score and field "myfactories" would have the number of factories. The 3 items would be separated by commas.

To get them back, you would: put URL "file"mysavefile.dat" into myData at which point you can do your math. Since Livecode works so well with text chunks you can use "item" to get things done. If you increase score every 20 seconds, you could do it as follows.

put ((the seconds - item 1 of mydata) / 20 * item 3 of myData * .2) + item 2 of myData into field "score"

Item 1 of myData was the time your app was shut down represented in seconds. item 3 of the variable myData is the number of factories. 20 is how often you update the score, and .2 is how much score to add. Add it to the previous score, and pop it into the score field.

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

Re: [Help]Creating a clicker game

Post by dunbarx » Sat Aug 29, 2015 10:12 pm

You hsve not the basics of LC, is all. But when you say you have never heard of the "seconds", or do not know anything about these factories, that is because we are, in fact, just giving hints. The foundation is missing. So the hints are not quite useful, yet, because you cannot speak the language yet.

There are entire threads on the issue of LiveCode seeming to be so English-like and accessible that new users jump in above their heads and immediately get stuck.

So.

The "seconds" is a function, Please read about it in the dictionary.

Now then, following Sturgis' hint, make a test stack with two fields. In the card script:

Code: Select all

on openCard
KeepTrack
end openCard

on keepTrack
     add  1 to fld 2
put the seconds & return after  fld 1
end keepTrack
Save the stack and close. Open it again. Save and close. The openCard handler is loading the seconds into one field, and incrementing the other. This is a hint. You have to learn enough to use it.

In one sense this is a lesson. In another sense, it is a wake-up call. You are beyond your abilities. You are not the first. Don't get discouraged. I will not let go, neither will most others. But we will, as I mentioned earlier with all those silly emoticons, start expecting much more homework from you. It will take considerable effort to become moderately proficient. The good news is that LC is indeed accessible, so when you do become moderately proficient, you will feel like a wizard.

Craig

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

Re: [Help]Creating a clicker game

Post by AgentItay » Sat Aug 29, 2015 10:38 pm

Thanks guys, I'll try this tomorrow, I truly appreciate your help :)

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

Re: [Help]Creating a clicker game

Post by AgentItay » Sun Aug 30, 2015 9:45 am

Hey, from what I see, this could work for only one "auto increcement" in a single stack, but I am going to do that way more than one time, and every button will increase it by another amount per second.
Now, don't tell me hints, just tell me if it is possible and I will try to go there from myself, and update you if I get results :).

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1682
Joined: Sat Feb 28, 2009 11:49 pm

Re: [Help]Creating a clicker game

Post by sturgis » Sun Aug 30, 2015 12:02 pm

Yes its possible. But heres the thing. You need to understand your own goal well enough to break the problem down into parts that you can solve. You said.. "This will only work for 1 auto increment, but there will be more for each button.."

if each button gives the same amount per second, its easy. To make it easy to understand.. How many seconds have gone by since the app was closed. If you have 1 button, and 1000 seconds have passed and a button pays 1 point per second, you have 1000 points. IF you have 3 buttons and 1000 seconds have passed, you have 3000 points.

If different types of buttons have different amounts that they score, you would have to track how many buttons of each type you have which is easily doable.

But heres the thing (and Craig has mentioned this several times..) you need to work on the basics. To learn how to move information around (which will be a huge part of your app) look in the dictionary for these things.

put
before (there are 2 entries, one is a keyword, thats the one you want to look at)
after
into

Learn how to put things into variables using those keywords.

You'll need to understand looping too.
look at repeat and the different ways it can be used:
repeat while
repeat until
repeat for each
repeat with
as well as using send to create a send in time loop. (probably the best way to create a game loop)

There are LOTS of task based lessons you can look at,( lessons.livecode.com )but if you don't know what you need to do to solve your problem (and thats all programming is really.. Understanding something well enough to tell the computer how to do it. If you don't have the problem broken down to the point where you know what needs to be done, you can't tell the computer how to do it)

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 » Sun Aug 30, 2015 1:33 pm

At the risk of repeating myself, I'd like to say that this site: https://sites.google.com/a/pgcps.org/livecode/ Covers just about all of the topics that Sturgis has recommended, and it is specifically geared towards beginners making games. It really is a great resource for learning the basics, while there is no exact "cookie clicker" type example stack, the lessons will teach you all you need to know in order to build your own.

--sefrojones

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1682
Joined: Sat Feb 28, 2009 11:49 pm

Re: [Help]Creating a clicker game

Post by sturgis » Sun Aug 30, 2015 2:11 pm

Nice site, good layout. Have you thought of putting together a book? (you can e-publish pretty easily, and/or let people pay for a printing if they want paper)

Does seem to be a great site to learn from.

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 » Sun Aug 30, 2015 2:36 pm

The site is not mine, but is put together by Cyril Pruszko. I believe his e-mail is at the top of the page. :D

--Sefro

Post Reply

Return to “Talking LiveCode”