actionscript 3 - AS3 variables from array not updating, even when given direct "command" -
i hope you're well. i've problem not understand. variables seem update don't (i've explained further in context in code below). [i'm trying create store users can buy bosses game].
i hope can me :)
here code. not hesitate ask me further details (number total of bosses around 36).
var bossbuybtnarray:array=[campagnesbuy.boss1, campagnesbuy.boss2]; //array movieclips used button buy var pbarray:array=[campagnesbuy.pb1, campagnesbuy.pb2]; //array movieclips tells if boss owned or not var bossvar:array=[sp[59], sp[60]]; //array int variables needed save state of inventory each(var storebtn: movieclip in bossbuybtnarray) storebtn.addeventlistener(mouseevent.click, fnbossstorebtn); //when user click on store buttons, function fnbossstorebtn(e: event): void { var listelementboss: displayobject = e.target displayobject; //listeelementboss = selected boss. var iboss: int = bossbuybtnarray.indexof(listelementboss); //get index of selected boss if (iboss < 0) { //check if selected boss in array listelementboss = e.currenttarget displayobject; if (listelementboss) iboss = bossbuybtnarray.indexof(listelementboss); } if (iboss < 0) return; if(pbarray[iboss].currentframe == 1){ //check if boss not owned. if (sp[58]>999){ //check if user has enough gold. /*the part doesn't work : */ bossvar[iboss] = 1; //modify variable (sp[59] or sp[60]) //normally update variable, let's sp[59] if boss 1 selected. //the interface modified fnalreadyowned (see below) guess updated, //but when trace(sp[59]), says 0, , writeobject() function saves 0. meaning //when reload game, gold gone, boss locked again. /*the rest works*/ sp[58] = sp[58] -1000; //substract cost of boss total gold. gamemode.piratetxt.text = sp[58]; //update gold "inventory" writeobject(); //save state of gold , boss ownership fnalreadyowned(null);// updates interface }else{ trace("not enough gold"); //if not enough gold } }else{ trace("already owned"); //if boss owned. } }
when this:
var bossvar:array=[sp[59], sp[60]]; //array int variables needed save state of inventory
you take variables sp
array , put them in bossvar
array. int variables copied in case.
that means changing either sp[59]
or bossvar[0]
won't change other.
example code:
var a:array = [1, 2]; var b:array = [a[0], 5]; a[0] = 42; trace("a[0] =" + a[0]); trace("b[0] =" + b[0]);
you circumvent storing objects example.
Comments
Post a Comment