Issue641

Title (continuesly) execute certain lua code with time delay
Priority feature Status resolved
Assigned To Xenux Keywords
Linked issues Watchers Xenux

Submitted on 2013-02-03 17h04 by matthiaskrgr, last changed by jesusalva.

Messages
Author: matthiaskrgr Date: 2013-02-03   17h04
I'd like to be able to execute lua code with certain time delay (without having
to re-trigger something and also be able to do that in a while loop ( for
example while x is true, let certain message appear every 40 seconds until x is
false).
Author: fluzz Date: 2013-10-08   14h37
On 02/03/2013 06:04 PM, Matthias Krüger - Roundup wrote:
>
> New submission from Matthias Krüger <matthias.krueger@famsik.de>:
>
> I'd like to be able to execute lua code with certain time delay (without having
> to re-trigger something and also be able to do that in a while loop ( for
> example while x is true, let certain message appear every 40 seconds until x is
> false).
>

In what kind of scripts will you use it ?
With triggered events ?
Author: matthiaskrgr Date: 2013-10-08   22h11
Uhmm, I'm not sure what kind of use case I had in mind then...
But for example by having something like
set_bot_destination("foo")
wait(sometime)
set_bot_destination("bar")
wait(sometime)
set_bot_destination("qux")

we could imitate complexe pathgfinding or simuare one npc "visiting" another one
and then walking back to the original waypoint (whereas this very example would
be easier to do with some  has_npc_reached_label?(bla) function)
Author: Xenux Date: 2013-10-18   12h27
I don't think your example are related to lua code. We need a way to trigger thing 
when bot enter a area (and leave). As I've mentioned on irc, we have two solution, 
extends the label trigger to be used with bot or make a new waypoint trigger.
Author: Xenux Date: 2013-10-18   12h28
*to lua code executed continuesly
Author: matthiaskrgr Date: 2013-10-19   01h45
Mmh ok.
Waypoint triggers could be used to work around things a bit but it won't offer
the same diversity of new options that something like a sleep option would have imo,
Author: salimiles Date: 2013-12-04   06h16
If I understand this request correctly, you want something like a
"lua_animation.lua" script, that would run continuously (aka, once every tenth
of  as second), and probably would be used for things on some sort of cyclical
cycle.

The idea would be you'd break things down by frequency.  An example to change a
bot's move target every 60 seconds:

jack_move_targets = {"Jack1", "Jack2", "Jack3", "Jack4"}
if (every_seconds(60)) then  --things that happen once a minute
  set_bot_destination("Jack", jack_move_target[jack_number])
  jack_number = jack_number + 1;
  if (table.getn(jack_move_targets) < jack_number) then
      jack_number = 0;
  end
end

-- This would require a lua function "every_seconds()", which would return true
once every x seconds.

This would be straightforward to add to what is currently called
"run_time_delay_events()"  Might be more difficult to troubleshoot though. :-)
Author: jesusalva Date: 2014-06-26   23h07
every_seconds() would store game_time() when first called and:
old_game_time=game_time()
while TRUE {
  if game_time() >= old_game_time + time_to_delay
}

Although we would not used a while?
Author: jesusalva Date: 2017-07-03   14h04
Pushed a very slightly modified version from /r/2346 (authored by Xenux) in
commit 1ae5bcc4a40d83966c6d0d31160ab86f8db009ea

Also fixes priority - it's not "minor", it's a feature request! ;-)
History
Date User Action Args
2017-07-03 14:04:31jesusalvasetstatus: open -> resolved
priority: minor -> feature
messages: + msg3471
nosy: + Xenux
assignedto: Xenux
2014-06-26 23:07:08jesusalvasetmessages: + msg2825
2013-12-04 06:16:15salimilessetmessages: + msg2644
2013-10-19 01:45:58matthiaskrgrsetmessages: + msg2620
2013-10-18 12:28:28Xenuxsetmessages: + msg2618
2013-10-18 12:27:47Xenuxsetmessages: + msg2617
2013-10-08 22:11:05matthiaskrgrsetmessages: + msg2614
2013-10-08 14:37:07fluzzsetmessages: + msg2608
2013-02-03 17:04:28matthiaskrgrcreate