Swift trying to cross check array of SKActions with array of strings -


hi i'm trying pick skaction array of skaction's using string.

i have array game's possible skactions in it. need pull out particular actions match selected node's possible action names (strings).

so, example, might have

allactions = [runcentre, runleft, runright]  

whereby skactions, and

possibleactions = [runcentre, runright]  

which strings accessed property list relating given node type.

how query allactions array values in possibleactions? know mechanics of iterating through both arrays not try access. can give skactions string property somehow? tried

runstraight.setvalue("runstraight", forkey: "name")   

but throws nsunknownkeyexception. there better way this?

any appreciated!

i don't understand want achieve. unfortunately skaction don't have tag or name property identification. can create dictionary associate string key skaction

suppose have these actions:

let runcentre = skaction.move(to: cgpoint(x:100.0,y:100.0), duration: 1.0) let runleft = skaction.move(to: cgpoint(x:0.0,y:100.0), duration: 1.0) let runright = skaction.move(to: cgpoint(x:200.0,y:100.0), duration: 1.0) let runtop = skaction.move(to: cgpoint(x:100.0,y:200.0), duration: 1.0) let runbottom = skaction.move(to: cgpoint(x:100.0,y:0.0), duration: 1.0) // create dictionary (key:string, value:skaction) let allactions = ["runcentre":runcentre,"runleft":runleft,"runright": runright,"runtop":runtop,"runbottom":runbottom] 

you can build dictionary with:

let allactions = ["runcentre":runcentre,"runleft":runleft,"runright": runright,"runtop":runtop,"runbottom":runbottom] 

now suppose have node these possible actions:

let rundiag = skaction.move(to: cgpoint(x:0.0,y:200.0), duration: 1.0) let possibleactions = ["runcentre":runcentre, "runright": runright, "rundiag":rundiag] 

to know possibleactions available in allactions (relying on equal keys) do:

let availableactions = allactions.filter { possibleactions.keys.contains($0.key) } 

Comments