Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (AndrewAMD, TipmyPip), 12,420 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
generate a string name #113939
02/26/07 11:54
02/26/07 11:54
Joined: Dec 2006
Posts: 40
viktoria Offline OP
Newbie
viktoria  Offline OP
Newbie

Joined: Dec 2006
Posts: 40
Are there any possibilities to generate a string name as in example:
Code:
   
string Question1 = "Some text1";
string Question2 = "Some text2";
string Question3 = "Some text3";

var i=1;
text question1Txt
{ strings = 1;
string = "Question"+i; //return "Some text1"
}
i=2;
text question2Txt
{ strings = 1;
string = "Question"+i; //return "Some text2"
}




Re: generate a string name [Re: viktoria] #113940
02/26/07 12:32
02/26/07 12:32
Joined: Jan 2003
Posts: 4,305
Damocles Offline
Expert
Damocles  Offline
Expert

Joined: Jan 2003
Posts: 4,305
What do you want to do with the texts in the end?

Do you want to display a number of questions,
such that the engine fills in a questionstring into one
of the 3 texts?

For a quiz game?

Re: generate a string name [Re: Damocles] #113941
02/26/07 13:19
02/26/07 13:19
Joined: Dec 2006
Posts: 40
viktoria Offline OP
Newbie
viktoria  Offline OP
Newbie

Joined: Dec 2006
Posts: 40
I want to show the content of Question+i string in my programm.
I have many questions and i must select 2 from they. var i will be generated per random 2 times and corresponding questions will be shown.
For example:
Code:
 
string Question1 = "Some text 1";
...
string Question10 = "Some another text 10";

var i = int(random (10)); // for example return 5
draw_text("Question" + i,100,10,vector(100,100,255));
var j = int(random (10)); // for example return 10
draw_text("Question" + j,100,10,vector(100,100,255));


// as result i want to see:
Some text 5
Some another text 10

My question is how can i call the right string in draw_text or in text{ string=....} block?

Re: generate a string name [Re: viktoria] #113942
02/26/07 17:40
02/26/07 17:40
Joined: Jan 2003
Posts: 4,305
Damocles Offline
Expert
Damocles  Offline
Expert

Joined: Jan 2003
Posts: 4,305
Here is a little simple script, that
will display a random question out of
a list of questions when pressing space.
Could be optimized using pointer arrays.
But I hope you will get the basic point behind it.





font ArialFont = "Arial", 1, 14;

Text Qustion_display
{
font = ArialFont;
layer = 3;
pos_x = 10;
pos_y = 10;
offset_y = 0;
strings = 1;
flags = visible;
}




string question_0="Are you smart?";
string question_1="Do you want to....?";
string question_2="11111";
string question_3="22222";
string question_4="33333";
string question_5="blabla";


string* the_question;
function select_question(number)
{

if(number==0){the_question=question_0;}
if(number==1){the_question=question_1;}
if(number==2){the_question=question_2;}
if(number==3){the_question=question_3;}
if(number==4){the_question=question_4;}
if(number==5){the_question=question_5;}


}


function display_question
{
select_question(int(random(6))); //chooses a random question between 0 and 5
Qustion_display.string[0]=the_question; //write the questionstring into the textpanel

}



on_space display_question();

Re: generate a string name [Re: Damocles] #113943
02/26/07 22:37
02/26/07 22:37
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Here's another idea...

Code:

string the_question;
string tStr;
function select_question(number)
{
str_for_num(tStr, number);
str_cpy(the_question, "str_cpy(tStr, question_");
str_cat(the_question, tStr);
str_cat(the_question, ");");
execute(the_question);
str_cpy(the_question, tStr);
}




This will work with any number of strings, without using a ton of "if" statements.

Last edited by xXxGuitar511; 02/27/07 15:21.

xXxGuitar511
- Programmer
Re: generate a string name [Re: xXxGuitar511] #113944
02/27/07 09:17
02/27/07 09:17
Joined: Dec 2006
Posts: 40
viktoria Offline OP
Newbie
viktoria  Offline OP
Newbie

Joined: Dec 2006
Posts: 40
Thanks a lot, xXxGuitar511, it was what I had been looking for and it works!
There is only one correction:
str_for_num (tStr, num);
in place of
str_for_number(tStr, num);

Re: generate a string name [Re: viktoria] #113945
02/27/07 15:21
02/27/07 15:21
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
ah, thanks for the correction...


xXxGuitar511
- Programmer

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1