ID:1713406
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
 
animate(Object, var1=new_value1, var2=new_value2, ..., time, loop, easing)

I'm sure there's some excuse for this abomination, but it's quite annoying since it means it doesn't support positional arguments properly.

Ran into this recently when attempting to do something like this, which doesn't work since the list can't be made associative with identifiers to feed animate with named args (DM only supports strings and paths for associative lists, which is terrible but that's another request):

//For the curious, this is useful for abstracting animation sets and changing them dynamically

var/list/animation = list(
new_value1,
new_value2,
new_value3,
time,
loop,
easing,
)

/proc/animatize(X)
animate(arglist(list(X)+animation))
return


It'd be nice to stick the variable args after the strict ones to improve feng shui and allow calling this proc with positional arguments as well.

This seems to work:
world
maxx = 10
maxy = 10
maxz = 1
New()
new/obj(locate(5,5,1))

var/list/animA = list("pixel_x"=128, "time"=10, "loop"=-1, "easing"=CUBIC_EASING)
var/list/animB = list("pixel_x"=64, "time"=20, "loop"=-1, "easing"=LINEAR_EASING)
var/list/animC = list("pixel_x"=128, "pixel_y"=64, "time"=5, "loop"=-1, "easing"=SINE_EASING)

obj
icon = 'Person.dmi'
Click()
var/options = list("A"=animA, "B"=animB, "C"=animC)
var/choice = input("Which?") as null|anything in options
if(choice)
animatize(src, options[choice])

proc/animatize(object, list/animSet)
var/list/L = animSet.Copy()
L.Insert(1, object)
animate(arglist(L))


According to this post associative lists are a combination of a red-black tree and an array, so they'll maintain insertion order, and this code should be safe.

Also, you can use anything except a number as a key in an associative list.
In response to DarkCampainger
DarkCampainger wrote:
Also, you can use anything except a number as a key in an associative list.

Yeah, my mistake. Point was that DM doesn't support straight identifiers as keys, making the example impossible as written.
Thanks for the snippet. If it works, it means that's not necessary since arglist will feed the named arguments properly with the names as strings (though this is what i mean by "terrible": dm is too stringly-typed).

Request still stands though: positional arguments are much simpler and cheaper in situations like this.