Save-Point
Array to arguments for a method? - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Code Support (https://www.save-point.org/forum-20.html)
+--- Thread: Array to arguments for a method? (/thread-3613.html)



Array to arguments for a method? - PK8 - 07-08-2011

I feel like I've asked this before, and I'm sure I managed to make this work at least once. I don't think I remember how. Anyway, I'm trying to figure out how to turn an array into a set of arguments for a method.

Quick example I'm putting out there, just because it's something I'm trying to figure out: Turning this array
Code:
@sound = ["Audio/SE/002-System02", 80, 100]

into a set of arguments for
Code:
Audio.se_play(filename[, volume[, pitch]])



RE: Array to arguments for a method? - deValdr - 07-08-2011

Well you can do:
Code:
Audio.se_player(@sound[0], @sound[1], @sound[2])

If you want it automated you can use the eval(string) function which is used to execute a string as code.


RE: Array to arguments for a method? - PK8 - 07-08-2011

Val! Thanks, but I figured it out, sorry to say. I forgot about how useful *array can be.

Code:
somearray = [0, 1, 2]
method(*somearray)