Undefined token 'random' [SOLVED]

Started by Candle, Mon 10/01/2005 21:37:06

Previous topic - Next topic

Candle

---------------------------
Compile Error
---------------------------
There was an error compiling your script. The problem was in 'Global script':
Error (line 73): Undefined token 'random'
How do you defined the random ?
Code: ags

#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function random_look() {   //  This is used to generate random messages in the unhandled event
 random = Random(5);   //  this is line 73 
 if (random==0) Display ("Trust me, you don't wanna look at the %s.", name);
 else if (random==1) Display ("There's nothing important at the %s.", name);
 else if (random==2) Display ("Looking at the %s is a waste of time.", name);
 else if (random==3) Display ("There are no clues at the %s.", name);
 else if (random==4) Display ("Looking at the %s won't help.", name);
 else if (random==5) Display ( "OK, I looked at %s, now what?", name);
 }
function random_use() {  // same for the use mode
 random = Random(5);
 if (random==0) Display ("No time for experiments with the %s.", name);
 else if (random==1) Display ("I can't do anything with the %s.", name);
 else if (random==2) Display ("Using the %s now may freeze your computer.", name);
 else if (random==3) Display ("Are you sure that you want to use the %s?", name);
 else if (random==4) Display ("Use the %s now? You must be kidding.", name);
 else if (random==5) Display ("There's no way you can make me use the %s.", name);
}
 function pickup(){    // same for take mode
 random = Random(5);
 if (random==0) Display ("I don't wanna carry the %s around.", name);
 else if (random==1) Display ("Having the %s with me won't help.", name);
 else if (random==2) Display ("I can't take the %s, my inventory is full.", name);
 else if (random==3) Display ("Are you sure that you want to pick up the %s?", name);
 else if (random==4) Display ("Pick up the %s? Are you crazy.", name);
 else if (random==5) Display ("I feel to weak. I can't carry the %s.", name);
}

Barbarian

#1
There's a few ways in which you might use the random function.

As an example: Below is a snippit of code I was using for a game I'm working on, in which I use the "Random" command in selecting a thunder sound effect to be played:

// script for room: Repeatedly execute
if (IsTimerExpired(2)==1){
Ã, 
int thunder=Random(3);

if (thunder==0) {PlaySound(5);}
else if (thunder==1) {PlaySound(6);}
else if (thunder==2) {PlaySound(7);}
else if (thunder==3) {PlaySound(5);}
}


and below is another example of how I used the "Random" command in a timer:

SetTimer(1,Random(800+500));

   *PS: I think "Random" command my be case-sensative, so use a Capital letter "R" when entering the "Random" command.
Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

Candle

I don't under stand this random stuff . what would I use  for the code above ?

Barbarian

#3
Quote from: Candle on Mon 10/01/2005 22:09:06
I don't under stand this random stuff . what would I useÃ,  for the code above ?

I was just giving some example of how a Random command might be used, of course you would need to adjust it to fit in with your script / game. So, again as an example, you might use it in your script code such as:

Code: ags

int messages=Random(5);Ã,  Ã, //Ã,  this is line 73 
if (messages==0) Display ("Trust me, you don't wanna look at the %s.", name);
else if (messages==1) Display ("There's nothing important at the %s.", name);
else if (messages==2) Display ("Looking at the %s is a waste of time.", name);
else if (messages==3) Display ("There are no clues at the %s.", name);
else if (messages==4) Display ("Use the %s now? You must be kidding.", name);
else if (messages==5) Display ("There's no way you can make me use the %s.", name);

Ã,  Ã, etc....

So, give a "label" to the Random integer you're trying to define, in this case I gave it the label of "messages" by using:
int messages=Random(5);

Ã,  Ã, Well, hope that helps. I'm no scripting expert though, so if you still need help I'm sure someone else can offer better advice than me.

Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

strazer

Yes, you have to declare a variable before you can use it:

  int random;

You can also combine the declaration with the assignment of a value:

  int random = Random(5);

Candle

That you Strazer . just had to add  and it works now ..
int random;
int name;

SMF spam blocked by CleanTalk