Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, 7th_zorro, dr_panther), 1,297 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Random Names #121345
04/04/07 00:32
04/04/07 00:32
Joined: Aug 2006
Posts: 128
Papua New Guinea
I
Impaler Offline OP
Member
Impaler  Offline OP
Member
I

Joined: Aug 2006
Posts: 128
Papua New Guinea
hi everyone,
I am making a first person shooter set in WWII in Normandie, and I want to be able to have a big library of names for soldiers, so that messages can come up like "You killed <name>" and that. The only problem is, I want to give random names to soldiers without having to script:

my.skill1 = int(random(100))
if(my.skill1 == 1)
{my.name = <something>;}
if(my.skill1 == 2)
{my.name = <something else>;}


and so on until 100. That would be really long and ugly code. is there an easier way to do this?


Murphey's Law:
<< if anything can go wrong, it will >>

(Murphey was an optimist).
Re: Random Names [Re: Impaler] #121346
04/04/07 01:33
04/04/07 01:33
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
You could load them from a random line in a text file, but you'd still be doing the same thing.


xXxGuitar511
- Programmer
Re: Random Names [Re: xXxGuitar511] #121347
04/04/07 04:35
04/04/07 04:35
Joined: Aug 2004
Posts: 2,215
I
ISG Offline

Expert
ISG  Offline

Expert
I

Joined: Aug 2004
Posts: 2,215
You could randomize a number, and that random number be == to a variable temp.

EX:
random(100); //get number
random == temprand; //something that works like this..

Then after it's set to a variable you can then open up a text document (like Guitar said) and have it go to the line that the random number said, so something like this:

Go To Line Number #TempRand //Not in code form but you can interpret it somehow

Then it can pick up that name randomly and simple...all you have to do mainly is place all the names in a text. If I had more time and wasn't so tired, or in a rush to get to sleep before waking up for work, I would do a sample for you.

Sorry if I wasn't much help.


Ground Tactics - Coming Soon
Ground Tactics OFFICIAL WEBSITE
Re: Random Names [Re: ISG] #121348
04/04/07 10:40
04/04/07 10:40
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Well I would read the whole text file into a string array at game start, so you don't have to read from the file during the game.
Code:

var names_max = 100;
string name_file = <my_names.txt>;

text names { strings=100; }

function names_store
{
var i;
var fhandle;

fhandle = file_open_read(name_file);
if(fhandle)
{
i = 0;
while(i < names_max)
{
file_str_read(fhandle,names[i]);
i += 1;
}
file_close(fhandle);
}
}

//Now in the game:
var randtemp;
...
randtemp = random(names_max);
str_cpy(my.string1,names[randtemp]);
//Now my.string1 contains a random name from the list



Re: Random Names [Re: Xarthor] #121349
04/05/07 06:46
04/05/07 06:46
Joined: Aug 2006
Posts: 128
Papua New Guinea
I
Impaler Offline OP
Member
Impaler  Offline OP
Member
I

Joined: Aug 2006
Posts: 128
Papua New Guinea
Thanks for those ideas! Storing the names in an array at the start of the game sounds like the best option


Murphey's Law:
<< if anything can go wrong, it will >>

(Murphey was an optimist).

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | 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