Difficulty Dividing

Monkey Forums/Monkey Programming/Difficulty Dividing

ewancordiner(Posted 2017) [#1]
https://drive.google.com/drive/folders/0B4SZhjiGhAlAZ1UybWptWFlqcms?usp=sharing

I am having difficulty within my clicking game as the update rate is set at 60. What I want to do is have auto going up once per second, so for example if auto was 1, the clicktotal would go up by one each second, not sixty. I have tried a number of different ways to implement this however I have reached no compromise. The updater rate needs to be 60 or relatively high as otherwise the clicking element will not work very well.


Gerry Quinn(Posted 2017) [#2]
I haven't looked at the code, but basically use something like this:

clickTotal = ( Millisecs() - startingMillisecs ) * auto / 1000

Don't use the number of updates to count, check the elapsed time during each update. The above will work even if updates are slow or irregular.


ewancordiner(Posted 2017) [#3]
Thanks Gerry, that's really helpful :)


ewancordiner(Posted 2017) [#4]
Hi Gerry, the code that you showed me works well for the automatic increasing, however it keeps making the actual user clicks reset to 0 for some reason. Not sure why this is.


Phil7(Posted 2017) [#5]
I think you have to add your userClick counter to the autogenerated clicks:
clickTotal = ( Millisecs() - startingMillisecs ) * auto / 1000 + userClicks


ewancordiner(Posted 2017) [#6]
That still doesn't appear to work, the automatic increase works but the clicking itself locks at what the current number is, e.g. it goes up then straight back down again.


Phil7(Posted 2017) [#7]
could you post your code of OnUpdate() in the gamestate?


ewancordiner(Posted 2017) [#8]
It's on the Google drive in 0.7 is it not?


Phil7(Posted 2017) [#9]
there is just mouseclicks = mouseclicks + clicktotal and I couldn't find any of the millisecs stuff.


ewancordiner(Posted 2017) [#10]
I took it out because it didn't work, I'll put it back in for you later. The line I used was
[Code] mouseclicks = (Millisecs () - 1 ) *auto / 1000 [/Code] this was in the bit above select game state so that it would be in effect on all pages.


Phil7(Posted 2017) [#11]
Could you put the whole project into a zip file, so I can download and test it easily in a working environment.
In about two hours I could help you out with a solution...


Gerry Quinn(Posted 2017) [#12]
The code I wrote just does auto clicks. If you have separate user clicks, you need to deal with them separately.

autoClickTotal = ( MilliSecs() - startingMillisecs ) * auto / 1000
userClickTotal += UserClicksThisUpdate()
clickTotal = autoClickTotal + userClickTotal




You could also have an ongoing way of counting autoclicks on some frames and adding them to the total, which would be easier in some respect for the future.


autoClickValue += ( Millisecs() - lastMillisecs ) * auto
lastMillisecs = Millisecs()

While autoClickValue > 1000
totalClicks += 1
autoClickValue -= 1000
Wend


Phil7(Posted 2017) [#13]
too late ;-)
I would also prefer the second option. Especially if you want to increase the auto value during the game.


ewancordiner(Posted 2017) [#14]
https://drive.google.com/file/d/0B4SZhjiGhAlAR3REV1RVemZoMTA/view?usp=sharing


ewancordiner(Posted 2017) [#15]
Just to ask Gerry, what are the starting millisecs and last millisecs you refer to? Should I make that a number?


Gerry Quinn(Posted 2017) [#16]
startingMillisecs is a field for each auto-clickable object. When the object is created you set it to the current value of Millisecs() [You'll have to tweak that if you pause the game, or save and reload - these are things that the second method - which doesn't use startingMillisecs - would make easier.

lastMillisecs is a field your game stores so it can tell exactly how long it was since the last update. Knowing that, you can tell when enough milliseconds have passed in total that an auto click should be registered.


ewancordiner(Posted 2017) [#17]
I think the easiest thing to do would be to start from scratch with these clicking mechanics and then implement them into the main game, currently I am having issue with getting both of them to work at the same time. However I don't know how to do this.


Phil7(Posted 2017) [#18]
I just changed some of your variable names, so I can understand the code easier. Hope this is what you wanted it to do...



ewancordiner(Posted 2017) [#19]
That works perfectly thankyou, I see what you did. I have never used the millisecs() before and so wasn't fully aware as of how to use it or whether variables needed to be set etc. Thank you :). For future reference, I was wondering what exactly what the [Code] Field flagGameStarted:Bool = False [/Code] meant. Does this make the automatic dollars go up only when enter has initially been pressed?


Phil7(Posted 2017) [#20]
Yes, that's it. Otherwise the automatic dollars would go up when the menu screen appears. You can test it by altering the line like this:
Field flagGameStarted:Bool = True


ewancordiner(Posted 2017) [#21]
Thankyou, it's for a computing project and I thought I had no chance doing that part of it haha!