Aller au contenu

Photo

Is this possible?


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
DM_Vecna

DM_Vecna
  • Members
  • 280 messages
 
I have ten string constants. They all end with a number 1-10 on the end to distinctify them. I am wondering if I can build a while loop to loop through them. Here is my question in code terms.

string sShop_resref_val1 =  SQLGetData(13);string sShop_resref_val2 =  SQLGetData(14);string sShop_resref_val3 =  SQLGetData(15);string sShop_resref_val4 =  SQLGetData(16);string sShop_resref_val5 =  SQLGetData(17);string sShop_resref_val6 =  SQLGetData(18);string sShop_resref_val7 =  SQLGetData(19);string sShop_resref_val8 =  SQLGetData(20);string sShop_resref_val9 =  SQLGetData(21);string sShop_resref_val10 = SQLGetData(22);

                        int nCount = 1;                        while (nCount != 11)                        {                        sTempStore = "sShop_resref_val"+IntToString(nCount);
                       take action here with the string
                       nCount++;
                       }

#2
DM_Vecna

DM_Vecna
  • Members
  • 280 messages
Wow, first post here and formatting is ...interesting.



Lets try this again.



string sShop_resref_val1 = SQLGetData(13);

string sShop_resref_val2 = SQLGetData(14);

string sShop_resref_val3 = SQLGetData(15);

string sShop_resref_val4 = SQLGetData(16);

string sShop_resref_val5 = SQLGetData(17);

string sShop_resref_val6 = SQLGetData(18);

string sShop_resref_val7 = SQLGetData(19);

string sShop_resref_val8 = SQLGetData(20);

string sShop_resref_val9 = SQLGetData(21);

string sShop_resref_val10 = SQLGetData(22);



int nCount = 1;

while (nCount != 11)

{

sTempStore = "sShop_resref_val"+IntToString(nCount);

speaksstring(sTempStore);

nCount++;

}

#3
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

DM_Vecna wrote...

Wow, first post here and formatting is ...interesting.


lol,  Yes but that is off set a bit by having no time limit on when you can edit your post.  So if it does not look the way you wanted just go back and edit the first one.  

I need  claififacation on your question.  Reason is you question does not match your post.

You stated: I have ten string constants.

then following in in your post you have only strings listed not constant strings. 

If you are trying to loop throw constant strings then the answer is no. 

Hmm  now that I think about it. Even trying to loop throw var strings the answer is no.  

Here is the reason:
When you create a varaiable in a script. The compiler does not keep a record of the name of the varaiable you used to identify it.  Your var names are nothing more then a lable that the compiler replaces with an off set to where it's value is stored on the stack.  in short once your script is compiled it no longer knows the name   sShop_resref_val3 It has it stored as something like 0x00008  
to loop through you vars dynamicly  by constructing the name. the code would have to know what the var names where, wich it does not.  


*Points down*  That will work for what you are tryung to do. 

Modifié par Lightfoot8, 25 juillet 2010 - 11:30 .


#4
Shadooow

Shadooow
  • Members
  • 4 468 messages
since you using database its easy...

string sTempStore;
int n = 13;
for(;n < 23;n++)
{
sTempStore = SQLGetData(n);
SpeakString(sTempStore);
}


Modifié par ShaDoOoW, 25 juillet 2010 - 10:17 .


#5
DM_Vecna

DM_Vecna
  • Members
  • 280 messages
Awesome ShaDoOoW



Thanks so much!!!!



Thank you also Lightfoot8. I also like being able to edit our posts.