• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Dynamically access object properties

BillFrams

Member
I am trying to do the following as I am coming from a js/node.js background and GML is quite similar to it, though I cannot access an object key with a dynamic string. The error it gives is "unable to convert string "jump" to int64" as it expects an integer index, though I want a string object property. I am new to Game Maker Studio 2, so I would appreciate some assistance; looking online didn't seem to provide relevant info.

GML:
var directions = {
    jump: "w",
    crouch: "s",
    left: "a",
    right: "d"
}

var action = "jump";

show_debug_message(directions[action]);
 
Top