GML A problem with randomizing

T

TonyCold

Guest
Well, I am trying to make an "obj_textgenerator" that has a variable called "Name", I want this variable to be Randomized and I also want to draw something like. draw_text(0,0, string(Name) + " is attacking your town(or something like that. You got me.)") So, what I basically want is to show that text for 5 secs then hide it for 10 secs then show it again ofc with the Randomized Name variable. I did that and tried to put "Name" in the create event but it always generates the same Name I put it in the step event and it keeps being shown for like a second .. I was wondering if anyone can show me a possible way to implement this.
 
you can deal with the display timer using alarms. other than that, you can pick random names using choose(name1, name2, name3...) and to use that name, you would just assign it to a variable then draw text etc. I hope thats what you are looking for.
 
put randomize() somewhere in your game, like in the create event of your controller object. That way, every time you start up your game, the result of random functions will have different values. Without randomize(), you will start with the same random seed every time, in which case you will get the same sequence of results out of calls to random functions (assuming the calls happen in the same order).
 
T

TonyCold

Guest
First of all thanks. Second, of all, I don't want to randomize it just every time I launch the game but every 7 Seconds or so. That's my code for the Controler Object
Create Event
Code:
showtext = true
Draw GUI Event
Code:
if (showtext = true){
    draw_text(100,100,choose("Jack","Tony","Vector","Gumball" + " is taking over" + choose("Spain","England","France")))
    alarm[0] = 50
else{
    alarm[1] = 75
}
}
Alarm[0] Event:
Code:
showtext = false
Alarm[1] Event:
Code:
showtext = true
However, it seems that I am missing something so those "Chooses" keep being generated so fast ignoring my alarms. Any help?

 
ok, the choice needs to be made only once during a cycle. So, how about put it in the alarm[0] event?

name = choose( nam1, nam2, ... );

then later use the name variable in your draw_text function.
 
T

TonyCold

Guest
ok, the choice needs to be made only once during a cycle. So, how about put it in the alarm[0] event?

name = choose( nam1, nam2, ... );

then later use the name variable in your draw_text function.
That's how I edited it. Still not working.
Create Event
Code:
showtext = true
name = choose(name1,name2,name3,......)
Draw GUI Event
Code:
if (showtext = true){
   draw_text(100,100,choose(string(name) + " is blah blah blah" ))
   alarm[0] = 50
else{
   alarm[1] = 75
}
}
Alarm[0] Event:
Code:
showtext = false
name = choose(name1,name2,name3 ..........)
Alarm[1] Event:
Code:
showtext = true
Now, It's not generating so fast but is generating those "Names" from the Create event but they are still not disappearing after a while and then appear again. I am Completely Lost.
 

RangerX

Member
First of all, the function randomize(); should be used once like when the game opens. This does not influence your random directly, it just randomly create a seed from which the random in the game will come from.
Second, when you test your build, you will always get the same seed. Its a debugging feature. If you'd play your game for real, its gonna be different each time.


Create Event:
Code:
showtext=false;
name=0;
alarm[0]=number of steps;

Draw Event:
Code:
if(showtext==true)
then
{
draw_text(name, etc);
}

Alarm[0]:
Code:
name=choose(name1,name2,name3);

if(showtext==false)
then
{
showtext=true;
alarm[0]=number of steps;
}
else
{
showtext=false;
alarm[0]=number of steps;
}

So basically, here is the explanation:
"name" should be declared in the Create Event so it can be used in any event in that object.
The draw event only need to draw "name" when it is allowed, nothing else.
Since you want the variable "name" to contain a different name each time the permission to draw is given, set it in the corresponding alarm.
The alarm sets the permission to true of false, depending the situation. No need to waste 2 alarms.
Lastly, notice I call the alarm again within the alarm. My example there is made so if you want a different wait time for when the permission is "true" and the permission is "false", you can put a different "amount of steps". If you always want to same amount of time, simply put one line at the end calling the alarm anew.
 
T

TonyCold

Guest
First of all, the function randomize(); should be used once like when the game opens. This does not influence your random directly, it just randomly create a seed from which the random in the game will come from.
Second, when you test your build, you will always get the same seed. Its a debugging feature. If you'd play your game for real, its gonna be different each time.


Create Event:
Code:
showtext=false;
name=0;
alarm[0]=number of steps;

Draw Event:
Code:
if(showtext==true)
then
{
draw_text(name, etc);
}

Alarm[0]:
Code:
name=choose(name1,name2,name3);

if(showtext==false)
then
{
showtext=true;
alarm[0]=number of steps;
}
else
{
showtext=false;
alarm[0]=number of steps;
}

So basically, here is the explanation:
"name" should be declared in the Create Event so it can be used in any event in that object.
The draw event only need to draw "name" when it is allowed, nothing else.
Since you want the variable "name" to contain a different name each time the permission to draw is given, set it in the corresponding alarm.
The alarm sets the permission to true of false, depending the situation. No need to waste 2 alarms.
Lastly, notice I call the alarm again within the alarm. My example there is made so if you want a different wait time for when the permission is "true" and the permission is "false", you can put a different "amount of steps". If you always want to same amount of time, simply put one line at the end calling the alarm anew.
I just checked that code and understood it well. However, Since I am using a lot of "Randomized elements" for my text (some are short and the others are pretty long) my text looks ugly and not well aligned. Sometimes it just goes out of the room and other times it almost inside my room. I was thinking to use the string_width but since It keeps getting Generated I got a bit confused. Any help with that?
 

RangerX

Member
In the function "draw_text_ext", you can decide the maximum lenght the text can take and it auto-wraps the next line.
 
T

TonyCold

Guest
In the function "draw_text_ext", you can decide the maximum lenght the text can take and it auto-wraps the next line.
That's true. However, It's something that is uhmm, supposed to be drawn in a single line. I was searching for like 3 hours without any Progress. Is there a way or should I go for Plan - B?
 

RangerX

Member
You saying its going outside the screen. Therefore there's not enough place? Unless you draw the text smaller or change lines I guess?
 
T

TonyCold

Guest
You saying its going outside the screen. Therefore there's not enough place? Unless you draw the text smaller or change lines I guess?
What I am basically saying is that I have a lot of randomized elements in my text so it simply has different lengths. I want ALWAYS to draw the text after around 32 pixels of the room borders. That's it.
 
F

FabioF

Guest
do you need a sort of "text justify" script? as @RangerX say, draw_text_ext simpy split text when you need to split. Every other manner to modify strings need a complex script that can be found in the marketplace. On the other hand there are functions like draw_set_haligh and draw_set_valigh useful if you need an automatic system for place the text in the game window. Anyway , in theory, you should check the with of your text pieces and if the sum of them is longer than "room_width-32" or "(view_xview+view_wview)-32" you need to change them until the sum meet your condition.
 
Top