actionscript 3 - How to make if chains -
i making game assignment in as3.0 , isn't working. variables , buttons defined, no error dose not function :
frame 2 layer 1
function checkscene():void { p_hp = 5 e_hp = 1 a_d = 1 if(p_hp == 5) if(e_hp == 2) if(a_d == 1) q = 1 if(p_hp == 5) if(e_hp == 1) if(a_d == 1) q = 2 }
frame 2 layer 2
stop(); but.addeventlistener(mouseevent.click, fl_clicktogotoandstopatframe); function fl_clicktogotoandstopatframe(event:mouseevent):void { gotoandstop(5); }
frame 3 layer 2
button_2.addeventlistener(mouseevent.click, fl_clicktogotoandstopatframe_2); function fl_clicktogotoandstopatframe_2(event:mouseevent):void { if(q == 1) gotoandstop(5) if(q == 2) gotoandstop(4) }
basically goes frame 4 if works, or 5 if doesn't. if chain isn't working. have no clue how because sort of thing works in excel (for checking multiple variables before execution).
see comments , explanation:
//use naming conventions : methods start lower-case. //fix method signature private void checkscene() { //declare variables //use naming conventions : variables start lower-case. int p_hp = 5; // ; @ end of every statement int e_hp = 1; int a_d = 1; int q = 0; if(p_hp == 5) { if(e_hp == 2) { if(a_d == 1) { q = 1; } } } //you use equivalent , shorter format: //if( p_hp==5 && e_hp==2 && a_d==1) q=1; if(p_hp == 5) { if(e_hp == 1) { if(a_d == 1) { q = 2; } } } //you use equivalent , shorter format: // if( p_hp==5 && e_hp==1 && a_d==1) q=2; //add printout check result system.out.println("q "+q); }
for future questions pleas post mcve
Comments
Post a Comment