espace Posted June 16, 2018 Share Posted June 16, 2018 hi, assuming i have this : var wait = function (callback, duration) { setTimeout(callback, duration); } wait(() => { o.paper[0].body.moves = false }, o.opponent_actions[0]) wait(() => { o.paper[0].body.moves = true }, 100 + o.opponent_actions[0]) wait(() => { o.paper[0].body.moves = false }, o.opponent_actions[0] + o.opponent_actions[1]) wait(() => { o.paper[0].body.moves = true }, 200 + o.opponent_actions[0] + o.opponent_actions[1]) wait(() => { o.paper[0].body.moves = false }, o.opponent_actions[0] + o.opponent_actions[1] + o.opponent_actions[2]) //etc.... how to automate that depending of o.opponent_actions.length? Quote Link to comment Share on other sites More sharing options...
losthope Posted June 17, 2018 Share Posted June 17, 2018 a loop in a loop maybe? i have no idea what your code tries to achieve, nor am i a professional programmer. here is pseudo code that roughly shows how i would try to automate it for(let j = 0; j < o.opponent_actions.length; ++j) { let summed_actions = 0; for(let i = 0; i < j; ++i) summed_actions += o.opponent_actions[i]; wait(() => { o.paper[0].body.moves = false; }, summed_actions); wait(() => { o.paper[0].body.moves = true; }, 100 + j*100 + summed_actions); } or maybe for(let j = 0; j < o.opponent_actions.length*2; ++j) { let summed_actions = 0; for(let i = 0; i < j/2; ++i) summed_actions += o.opponent_actions[i]; if(j % 2 == 1) summed_actions += 50 + j*50; wait(() => { o.paper[0].body.moves = j % 2 == 1; }, summed_actions); } espace 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.