help with drawing text

S

stoves

Guest
i am drawing text and playing music by pressing enter, but i need to write code to where i press enter again, it will delete the previous string and draw a new one.
here is my draw event :

var str1 = "Welcome to Delphi!#You are about to enter the sanctuary."

draw_self();

if (showtext == 1){
draw_set_halign(fa_center);
draw_set_font(fnt_pixel);
draw_text(x-32,y-32,str1);
}

step event :

if (distance_to_object(obj_player)<20) && keyboard_check(vk_enter) {

showtext = 1;
} else if keyboard_check(vk_shift) {
showtext = 0;
}

create event :

image_speed = .1;
showtext = 0;
 

Xer0botXer0

Senpai
You basically want to press enter once then text is drawn, again with other text, and so on ?

If this is the case then i assume you already have that text in a list or array or someplace ?
 
T

Ting_Thing

Guest
Can't you just do something like this?

if keyboard_check_pressed(vk_enter)
{
if str1 = "Welcome to Delphi!#You are about to enter the sanctuary."
str1 = "The second message"
else if str1 = "The second message"
str1 = "The third message"
else...
}

If you do this, you would want to remove "var" before str1 so that the string can be worked with in other events (namely, your step event or keyboard enter key event)
 

Xer0botXer0

Senpai
Thats not the best way.


Declarations:
Arr_msgs[0] = "blah blah"
Arr_msgs[1] = "blaaaaah blaaaah"
Var_count = 0;

Keypress event:

Var_count +=1

Draw event:

draw_text(x,y, Arr_msgs[Var_count])
 
S

stoves

Guest
Thats not the best way.


Declarations:
Arr_msgs[0] = "blah blah"
Arr_msgs[1] = "blaaaaah blaaaah"
Var_count = 0;

Keypress event:

Var_count +=1

Draw event:

draw_text(x,y, Arr_msgs[Var_count])
would i put the declarations in my create event?

so when i copy the code, do i replace var_count in the draw event, or do i leave it? whenever i leave it as var_count, it just displays my second message.
 
Last edited by a moderator:

Xer0botXer0

Senpai
It starts off displaying yhe first message, then you press enter and it displays the second one ? Thats what the code does. It iterates between meaaages atored in the 1D array via a keypress.
 
S

stoves

Guest
It starts off displaying yhe first message, then you press enter and it displays the second one ? Thats what the code does. It iterates between meaaages atored in the 1D array via a keypress.
okay, i get it now. thanks!

It starts off displaying yhe first message, then you press enter and it displays the second one ? Thats what the code does. It iterates between meaaages atored in the 1D array via a keypress.
how can i set a range for my array? for example, i have 3 strings of text. i need the value of var_count to stay between 0 and 3, and the clamp command just causes my game to crash.
 
Last edited by a moderator:
Top