Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by mtg101

I'm using an array of actions to control the monsters in my game. A vastly simplified version looks like:
actions: [{cmd: 'move', dir: 'left'}, {cmd: 'move', dir: 'up'}]

I was hoping to be able to set the actions from Weltmeister by setting a name/value pair as an array:
name: actions
value: [{cmd: 'move', dir: 'left'}, {cmd: 'move', dir: 'up'}]

However this just results with in action being set to the string '[{cmd: 'move', dir: 'left'}, {cmd: 'move', dir: 'up'}]'

So...
- does Weltmeister do array properties, and I'm just doing it wrong?
- does Weltmeister not do array properties so I'll have to use action1, action2, etc, properties?
- am I going about this in completely the wrong way?

Thanks in advance for any help.

1 decade ago by drhayes

I'm away from Weltmeister at the moment... but I think you can set:

name: actions.1.cmd
value: 'move'

name: actions1.dir
value: 'left'

I think you'll end up with an 'actions' array, similar to how triggers work. Since arrays in JS are mostly objects with keys set to numbers, I think you'll be okay. Maybe.

If not, then I'm more sure you can do:

name: actions.1
value: 'some value here'

Not sure how to set a more complex object property there, though.

1 decade ago by mtg101

Your remote Weltmeister knowledge is awesome!

As you say I can use:
name: actions.1
value: {cmd: 'move', dir: 'left'}

Exactly what I need -- thanks!

1 decade ago by mtg101

Ahh turns out that's not quite it. Despite programming for over 20 years I forgot you index arrays form 0 (#facepalm) and managed to mask what was really going on...

Anyway if you do:
name: actions.0
value: {cmd: 'move', dir: 'left'}

What you get is is actions[0] being a string not an object. So as a quick (and hugely insecure) fix I'm doing the following to convert to an object:
var actionObject = eval ( '(' + actions[0] + ')' );

If anyone knows how to set as an object directly from Weltmeister I'd love to know!
Page 1 of 1
« first « previous next › last »