# GMLscripts.com

Discuss and collaborate on GML scripts

You are not logged in.

## #1 2016-04-25 01:03:04

Member
Registered: 2016-01-30
Posts: 3

### finite timer scripts?

is there someone here that can help me write a finite timer scripts?
I need 3 scripts

timer_get(id,time)
timer_update_all()
timer_delete(id)

timer_get would create a timer and get a string ID and get a time or delay
it would then check if it was 0 or lesser. if it is then it would return true

timer_update_all would update all the timers created by timer_get if they were greater then 0

timer_delete would delete the timer with the given id

I have proto typed a script called wait(id,time) that is basically all three put together
however I am trying to separate them into three scripts so that it can be updated deleted and called in different positions

this is what I currently have

Expand///wait(string,time)
var ID = string(id)+argument0
var Time = argument1
if !ds_map_exists(global.timers,ID) {
}
else {
if ds_map_find_value(global.timers,ID) <= 0 {
ds_map_delete(global.timers,ID)
return true
}
else {
ds_map_replace(global.timers,ID,ds_map_find_value(global.timers,ID)-1)
}
}

the problem is that I can't find a way to iterate though all the ds_map(global.timers,ID) and subtract one from them.
since they use keys instead of indexs however I need these keys so that I can assign a id to them and be checked if they exist or not

Offline

## #2 2016-04-25 06:35:37

xot
Registered: 2007-08-18
Posts: 1,238

### Re: finite timer scripts?

OK, ds_map functions provide a simple way to iterate through all the keys without needing to know the keys in advance. The keys are not necessarily traversed in the order created, or in the same order each time, but they will allow you to process every element of a map.

Below is some basic structure that should help you finish your code. It is obviously not complete.

Expandkey = ds_map_find_first(map);
while (!is_undefined(key)) {
map[? key] = map[? key] - 1;
key = ds_map_find_next(map, key);
}

The "map[? key] = map[? key] - 1" accessor code above is equivalent to "ds_map_replace(map, key, ds_map_find_value(key) - 1)" but written more simply.

Abusing forum power since 1986.

Offline

## #3 2021-10-31 18:38:30

minasoltani
Member
Registered: 2021-10-31
Posts: 2

Offline