• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Scripting strategy with timers

Status
Not open for further replies.
Level 3
Joined
Jan 29, 2021
Messages
34
Hello guys. I continue working on my AI strategy on the 2D platformer map
Here is my first attempt that makes computer bot to complete the first level. The bot strategy looks pretty simple - first, move right, after some time make a jump(while still holding "right arrow pressed"), then after some time make another jump so on, after a while vise a versa moving to the left and making jumps.
The code looks like this
Code:
function Level_1_1_Comp_7 takes nothing returns nothing
local timer t1 = CreateTimer()
local timer t2 = CreateTimer()
local timer t3 = CreateTimer()
local timer t4 = CreateTimer()
local timer t5 = CreateTimer()
local timer t6 = CreateTimer()
local timer t7 = CreateTimer()
local timer t8 = CreateTimer()
local timer t9 = CreateTimer()
local timer t10 = CreateTimer()
local timer t11 = CreateTimer()
local timer t12 = CreateTimer()
local timer t13 = CreateTimer()
local timer t14 = CreateTimer()
local timer t15 = CreateTimer()

set Comp_Slot = 7

call Right()
call TimerStart(t1, 1.44, false, function Jump)
call TimerStart(t2, 3.36, false, function Jump)
call TimerStart(t3, 4.32, false, function Jump)
call TimerStart(t4, 5.28, false, function Jump)
call TimerStart(t5, 7.3, false, function Jump)
call TimerStart(t6, 7.8, false, function StopRight)

call TimerStart(t7, 9.0, false, function Left)
call TimerStart(t8, 9.3, false, function Jump)
call TimerStart(t9, 10.2, false, function Jump)
call TimerStart(t10, 10.88, false, function Jump)
call TimerStart(t11, 11.54, false, function Jump)
call TimerStart(t12, 13.2, false, function Jump)
call TimerStart(t13, 15.12, false, function Jump)
call TimerStart(t14, 17.94, false, function StopLeft)
call TimerStart(t15, 18.00, false, function Down)
endfunction

Here I wonder if I'm doing the right way
So, the question is - do I need to use many timers or how it can be done with one timer
 
Level 3
Joined
Jan 29, 2021
Messages
34
<Turn them into arrays and use hashtables/expiring timer for detection>
How to do it? Can you make a small example?
 
Status
Not open for further replies.
Top