Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Need help making a script
- AmazonJosh
-
Scratcher
23 posts
Need help making a script
I'm making a cookie clicker type game, if you know what I mean. In the project there is a store to buy products that increase cookie production, so lets say I have 5 products of one type, and each one gives the player 1 more cookie per second, but I need to have it register maybe 32 products, I don't want to make 32 scripts telling to give more per second (it would make the game slow) so I want to know how to make a key/equation that tells the game to add lets say x1 cookies per second per product. Help would be greatly appreciated.
- ErnieParke
-
Scratcher
1000+ posts
Need help making a script
What you need here is a handy variable. Let's name it CookiesPerSecond. Now, instead of 32 scripts, all you need is:
*drum roll*
That's all! Of course, you'll have to change other scripts a bit, but not much. Now, whenever you buy a product, you also have to increase (CookiesPerSecond) by how much cookies it makes. So:
And then when you sell a product, you subtract the same amount, and you're completely done. :)
Nice,
ErnieParke
*drum roll*
when gf clicked
set [CookiesPerSecond v] to (0)
forever
change [Cookies v] by (CookiesPerSecond)
That's all! Of course, you'll have to change other scripts a bit, but not much. Now, whenever you buy a product, you also have to increase (CookiesPerSecond) by how much cookies it makes. So:
change [CookiesPerSecond v] by (5)
And then when you sell a product, you subtract the same amount, and you're completely done. :)
Nice,
ErnieParke
Last edited by ErnieParke (Dec. 6, 2013 22:34:20)
- Centrifugal
-
Scratcher
500+ posts
Need help making a script
Okay here we go
//First you need a variable called increase per second
Set [Increase per second v] to [ ]
//Set it to 0 when the green flag is clicked whenever you broadcast to start your game
When gf clicked
Set [Increase per second v] to [0]
//Then whenever an item is clicked tell it to add however many clicks per second more you want to it
When this sprite clicked
If <(money)>(however much this item costs)>
Change [money v] by [Minus however much this item costs]
Change [Increase per second v] by [However much this increases clicks per second by]
end
//Hope this helps
Last edited by Centrifugal (Dec. 6, 2013 22:41:39)
- AmazonJosh
-
Scratcher
23 posts
Need help making a script
Although, I need my cookies per second to actually be something like- wait 0.2 sec- change cookies by 1, it's hard to explain, and I need that 0.2 seconds multiplied by the amount of products that makes 1 every 0.2 seconds as a script to increase the cookies by product x cookies per second, I'm trying to think of a script for that.
- KermitMC
-
Scratcher
100+ posts
Need help making a script
do what ernie said but instead of forever change cookies by CPS wait 0.2 secs change cookies by cps / 5
when gf clickedhope this helps
set [cps v] to [0]
forever
wait [0.2] secs
change [cookies v] by ((cps) / [5])
end
- AmazonJosh
-
Scratcher
23 posts
Need help making a script
I just found a script that seems to work now, thanks everyone!
- Discussion Forums
- » Help with Scripts
-
» Need help making a script