+ 2

Canvas and setTimeout & setInterval Functions

Say I have an object with a function. Inside of this function, I want to have a timed effect. In my animation loop, I will be calling this function every frame of animation. For whatever reason, I can't get it to work right with what I want. I'll attach the actual code I'm using it in as well. I'll also attach the one I'm using to get around it. I have boolean flags that control which function the object is using at any point (harvesting, returning home, or going to resource point). When the timeout happens, I want the flags to switch after the harvester has taken minerals. It's just taking all of the minerals available and not switching the booleans. Am I doing something stupid in javascript that I don't know about?? Working Code: https://code.sololearn.com/WwfE1I1vvyxA What I want, but broken: https://code.sololearn.com/WRnfxulb96Z0 The issue is in the this.harvest function in the harvester 'object'

13th Feb 2018, 2:33 AM
Zeke Williams
Zeke Williams - avatar
4 Answers
+ 9
You mean a timer?
13th Feb 2018, 2:29 PM
Bohdan Sakovych
Bohdan Sakovych - avatar
+ 8
Zeke, I didn't get you, you already have working code
13th Feb 2018, 6:32 AM
Bohdan Sakovych
Bohdan Sakovych - avatar
+ 1
@Bohdan But it's not the way I want to accomplish this task. I want to use a timeout function to do it.
13th Feb 2018, 2:19 PM
Zeke Williams
Zeke Williams - avatar
+ 1
Instead of subtracting from a number every frame until it's zero, I want to use a precise amount of seconds. A timeout function would do this, if I could get it to work. Are there any other ways that you know of? Yes, sort of like a timer.
13th Feb 2018, 2:38 PM
Zeke Williams
Zeke Williams - avatar