xml - Haxe Iteration of defining variables -


i have chunk of code parsing xml variables. on 1 of variables, there never more 12 there may less. trying define each of these variables multiple times second. need them defined if have variable because right now, if there less 12 variables, program crashes. right code below works, if there 12 values present in xml document. how itterate code don't have list of "if != null" statements?

var _vol1 = (ipts[0].volume); var _vol2 = (ipts[1].volume); .... .... var _vol12 = (ipts[11].volume); 

this code works when 12 values in xml document crashes if there less 12 might case.

how structure code define/redefine variable if there value , not null? what needs iterated????

if ((ipts[0].volume) != null ){     var _vol1 = (ipts[0].volume); } 

i researched on haxe website wasnt sure applicable. syntax , programming not greatest. help. sorry if bad question.

update: here complete code of now. doesn't crash not defining volume variables anymore added if statements

var xml = xml.parse(_vmixdata);  // wrap xml fast access var data = new haxe.xml.fast(xml.firstelement());  //getting data inputs (here getting xml node 'inputs', contain 2 'input' nodes, per sample xml file. var inputs = data.node.inputs; var ipts = new array<vinput>();  (input in inputs.nodes.input) {     var ipt = new vinput();     if (input.has.state) {         ipt.state = input.att.state;        ipt.value = input.innerhtml;             }     if (input.has.volume) {         ipt.volume = std.parseint(input.att.volume);           }     if (input.has.muted) {         ipt.muted = std.string(input.att.muted);           }     ipt.value = input.innerhtml;               ipts.push(ipt); }  var overlays = data.node.overlays; var ovlys = new array<voverlay>(); (overlay in overlays.nodes.overlay) {     var ovly = new voverlay();     if (overlay.has.number) {          ovly.number = std.parseint(overlay.att.number);     }     ovly.value = overlay.innerhtml;     ovlys.push(ovly); }  //defines variables based on returned information vmix var _fadetoblack:bool = data.node.fadetoblack.innerhtml == "true" ? true : false;  var _version = data.node.version.innerhtml; var _record:bool = data.node.recording.innerhtml == "true" ? true : false; var _external:bool = data.node.external.innerhtml == "true" ? true : false; var _stream:bool = data.node.streaming.innerhtml == "true" ? true : false; var _active:int = std.parseint(data.node.active.innerhtml); var _preview:int = std.parseint(data.node.preview.innerhtml);  var _overlay1 = (ovlys[0].value); var _overlay2 = (ovlys[1].value); var _overlay3 = (ovlys[2].value); var _overlay4 = (ovlys[3].value); var _input1state = (ipts[0].state);   if (ipts[0].volume != null ){ var _vol1 = (ipts[0].volume); } if (ipts[1].volume != null ){ var _vol2 = (ipts[1].volume); } if (ipts[2].volume != null ){ var _vol3 = (ipts[2].volume); } if (ipts[3].volume != null ){ var _vol4 = (ipts[3].volume); } if (ipts[4].volume != null ){ var _vol5 = (ipts[4].volume); } if (ipts[5].volume != null ){ var _vol6 = (ipts[5].volume); } if (ipts[6].volume != null ){ var _vol7 = (ipts[6].volume); } if (ipts[7].volume != null ){ var _vol8 = (ipts[7].volume); } if (ipts[8].volume != null ){ var _vol9 = (ipts[8].volume); } if (ipts[9].volume != null ){ var _vol10 = (ipts[9].volume); } if (ipts[10].volume != null ){ var _vol11 = (ipts[10].volume); } if (ipts[11].volume != null ){ var _vol12 = (ipts[11].volume); }  //var _1mute = (ipts[0].muted); //var _2mute = (ipts[1].muted); //var _3mute = (ipts[2].muted); //var _4mute = (ipts[3].muted); //var _5mute = (ipts[4].muted); //var _6mute = (ipts[5].muted); //var _7mute = (ipts[6].muted); //var _8mute = (ipts[7].muted); //var _9mute = (ipts[8].muted); //var _10mute = (ipts[9].muted); //var _11mute = (ipts[10].muted); //var _12mute = (ipts[11].muted);    if (ipts[2] != null){     var _ovly3 = 1; } //trace(ovlys[2].value); //trace(ovlys[0].value); //trace(ipts[0].state); //trace(_active); //trace(_preview); //trace(_fadetoblack); 

to @ each thing in xml, for (child in xml). have number of variables, need use array, not var1 through varinfinity.

you didn't post enough code, i'm guessing here:

var vararray = []; (child in xml) {     vararray.push(child.volume); } 

that way, doesn't matter how many variables have, code adapts (rather adapting adding var1, var2, etc).


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -