0 Replies Latest reply on Nov 24, 2009 8:24 PM by shintashi

# more trouble with for loops

This was my attempt:

function poor(){if(money < shopwin["prc"+\$].text){shopwin["itm"+\$].textColor = 0x999999;
shopwin["prc"+\$].textColor = 0x999999;}
if(money >= shopwin["prc"+\$].text){shopwin["itm"+\$].textColor = 0xFFFFFF;
shopwin["prc"+\$].textColor = 0xFFFFFF;}
}
for (\$=1;\$<9;\$++){poor();}

--------------------------------

at compressing this:

function poor(){

if(money < shopwin.prc1.text){shopwin.itm1.textColor = 0x999999;
shopwin.prc1.textColor = 0x999999;}
if(money < shopwin.prc2.text){shopwin.itm2.textColor = 0x999999;
shopwin.prc2.textColor = 0x999999;}
if(money < shopwin.prc3.text){shopwin.itm3.textColor = 0x999999;
shopwin.prc3.textColor = 0x999999;}
if(money < shopwin.prc4.text){shopwin.itm4.textColor = 0x999999;
shopwin.prc4.textColor = 0x999999;}
if(money < shopwin.prc5.text){shopwin.itm5.textColor = 0x999999;
shopwin.prc5.textColor = 0x999999;}
if(money < shopwin.prc6.text){shopwin.itm6.textColor = 0x999999;
shopwin.prc6.textColor = 0x999999;}
if(money < shopwin.prc7.text){shopwin.itm7.textColor = 0x999999;
shopwin.prc7.textColor = 0x999999;}
if(money < shopwin.prc8.text){shopwin.itm8.textColor = 0x999999;
shopwin.prc8.textColor = 0x999999;}

if(money >= shopwin.prc1.text){shopwin.itm1.textColor = 0xFFFFFF;
shopwin.prc1.textColor = 0xFFFFFF;}
if(money >= shopwin.prc2.text){shopwin.itm2.textColor = 0xFFFFFF;
shopwin.prc2.textColor = 0xFFFFFF;}
if(money >= shopwin.prc3.text){shopwin.itm3.textColor = 0xFFFFFF;
shopwin.prc3.textColor = 0xFFFFFF;}
if(money >= shopwin.prc4.text){shopwin.itm4.textColor = 0xFFFFFF;
shopwin.prc4.textColor = 0xFFFFFF;}
if(money >= shopwin.prc5.text){shopwin.itm5.textColor = 0xFFFFFF;
shopwin.prc5.textColor = 0xFFFFFF;}
if(money >= shopwin.prc6.text){shopwin.itm6.textColor = 0xFFFFFF;
shopwin.prc6.textColor = 0xFFFFFF;}
if(money >= shopwin.prc7.text){shopwin.itm7.textColor = 0xFFFFFF;
shopwin.prc7.textColor = 0xFFFFFF;}
if(money >= shopwin.prc8.text){shopwin.itm8.textColor = 0xFFFFFF;
shopwin.prc8.textColor = 0xFFFFFF;}
}

poor();

----------------------------------

I tried a similar code to the first (above) for the following list, but it also failed.

shopwin.itm1.text = m_shop.inv.itm1.nm; shopwin.prc1.text = m_shop.inv.itm1.prc;
shopwin.itm2.text = m_shop.inv.itm2.nm; shopwin.prc2.text = m_shop.inv.itm2.prc;
shopwin.itm3.text = m_shop.inv.itm3.nm; shopwin.prc3.text = m_shop.inv.itm3.prc;

//(I actually needed 5 more just like this for itm4 through itm8)

--------------------------------

I based the top code on this:

function buy(){if(actionBox == m_shop.inv["itm"+n].nm && money >= m_shop.inv["itm"+n].prc){
char.inv["itm"+n] = m_shop.inv["itm"+n]; money = money - m_shop.inv["itm"+n].prc;} ;}