Page 1 of 1

new const

Posted: 2011 Jan 24 21:02
by addinol
Sveiki, taigi padaryti su const 1 dalyką, sakykim turiu

Code: Select all

new const g_country_name[][] ={    "Finland",    "Sweden",    "Estonia"};

Code: Select all

 new const g_country_text[sizeof g_country_name][] ={    "FI05",    "SE05",    "EE05"};
Viename metode, gaunu iš kur žaidėjas yra su geoip_country (įsaugoju į iCountry[33]), sakykim gaunu ir gaunu Estonia, dabar aš jam noriu parodyti tokį tekstą:

You are from Estonia, your text is EE05... Kaip tai padaryti ?

Bandziau
"You are from %s, your text is %s", iCountry[id], g_country_text[iCountry] )
meta error... Array must be indexed (variable "iCountry")

Bet neveikia :(

Re: new const

Posted: 2011 Jan 24 21:44
by newb
Ka pas tave id rodo ?..

Re: new const

Posted: 2011 Jan 24 22:03
by aaarnas
Taip supratau norėjai su globaliu kintamuoju, kur laikoma žaidėjo šalis:

Code: Select all

new const g_country_name[][] ={    "Finland",    "Sweden",    "Estonia"}; new const g_country_text[][] ={    "FI05",    "SE05",    "EE05"}; new p_country[33] public funckcija(id) {        new country[45], ip[30]    get_user_ip(id, ip, charsmax(ip), 1)    geoip_country(ip, country, charsmax(country))        for(new i=0; i<sizeof(g_country_name); i++) {                if(equali(country, g_country_name[i])) {                        p_country[id] = i            break;        }    }        client_print(id, print_chat, "You are from %s, your text is %s", g_country_name[p_country[id]], g_country_text[p_country[id]])}

Re: new const

Posted: 2011 Jan 24 22:07
by addinol
Nu aš noriu padaryti, jog 1 eilutė iš names atitiktų text... Ta prasme jei žaidėjo country Estonia tada textas EE05, ir kaip tai padaryti

Nelabai supratau tą p_country[id] = i, ir ar būtina naudoti ta for()

Re: new const

Posted: 2011 Jan 24 22:18
by aaarnas
For naudojam, nes reikia rasti, kuris elementas yra šalies pavadinimas g_country_name masyve, o kadangi masyvo g_country_text numeriai taip pat atitinka, tai jei žinome elemento numerį g_country_name, tai įrašę jį į g_country_text mums duos reikiamą tekstą.

Re: new const

Posted: 2011 Jan 24 22:52
by addinol
ok, dėkui, lyg ir veikia :)