Legacy GM want to make textbox appear when player presses button

EZTALES

Member
hey yall,
i was just wondering if it was possible to make a line of text only appear when a player comes in contact with the object, and presses (in this case) Z;
my code is this at the moment, is saying the text with the player being on the object, but when i press Z it goes to the next line of text:
heres the code..
Code:
Create Event:
Var: Set text to a value of 1 that applies to the player that's not relative.
//all the variables
text=1
textmax=0
i=0
imax=0
str=''
nextsound=0
effect=0;
(next code action)
//all the strings
str[1]=" Howdy there!"
str[2]=" This is a textbox!"
str[3]=" did you know!"
str[4]=" The end."

//textmax's value should be how many strings you have.
textmax = 4;
Code:
Destroy Event
Var: set Variable to object player. the variable is named text and has a value of 0: it is not relative.

Stop sound: snd_plaintext.
Code:
step event (this is a big one)
destroy: object_interact:
Set variable text to 1
execute code:
imax=string_length(str[text])
if i<imax
{
i+=1
}

//for people who like z
if keyboard_check_pressed(ord('Z'))
{
if text=textmax{
if i=imax{
   instance_destroy();
}
}
else
{
 if text<textmax{
  if i=imax
   {
   text+=1
   i=0
   }
   }
 else
  {
  instance_destroy();
  }
 }
}

//for people who like enter
if keyboard_check_pressed(vk_enter)
{
if text=textmax{
if i=imax{
   instance_destroy();
}
}
else
{
 if text<textmax{
  if i=imax
   {
   text+=1
   i=0
   }
   }
 else
  {
  instance_destroy();
  }
 }
}

 
//for people who like x
if keyboard_check_pressed(ord('X'))
{
 i=imax
}

//for people who like shift
if keyboard_check_pressed(vk_shift)
{
 i=imax
}
Code:
Draw Event
draw_set_font(fnt_textbox_normal)

//normal text
if effect = 0{
draw_set_color(c_white);
draw_text(view_xview+0,view_yview+10,string_copy(str[text],0,i));
}
else
{
//shaky text
if effect = 1{
draw_set_color(c_white);
draw_text(view_xview+30+random_range(-1, 1),view_yview+170+random_range(-1, 1),string_copy(str[text],0,i));
}
else
{
//red text
if effect = 2{
draw_set_color(c_red);
draw_text(view_xview+30,view_yview+170,string_copy(str[text],0,i));
}
else
{
//yellow text
if effect = 3{
draw_set_color(c_yellow);
draw_text(view_xview+30,view_yview+170,string_copy(str[text],0,i));
}
else
{
//red shaky text
if effect = 4{
draw_set_color(c_red);
draw_text(view_xview+30+random_range(-1, 1),view_yview+170+random_range(-1, 1),string_copy(str[text],0,i));
}
else
{
//yellow shaky text
if effect = 5{
draw_set_color(c_yellow);
draw_text(view_xview+30+random_range(-1, 1),view_yview+170+random_range(-1, 1),string_copy(str[text],0,i));
}
else
{
//ghosty shaky text
if effect = 6{
draw_set_color(c_white);
randomize();
draw_text(view_xview+30+random_range(-1, 1),view_yview+170+random_range(-1, 1),string_copy(str[text],0,i));
draw_text_colour(view_xview+30+random_range(-1.25, 1.25),view_yview+170+random_range(-1.25, 1.25),string_copy(str[text],0,i),c_white,c_white,c_white,c_white,.5);
draw_text_colour(view_xview+30+random_range(-1.25, 1.25),view_yview+170+random_range(-1.25, 1.25),string_copy(str[text],0,i),c_white,c_white,c_white,c_white,.25);
}
else
{
//red ghosty shaky text
if effect = 7{
draw_set_color(c_red);
randomize();
draw_text(view_xview+30+random_range(-1, 1),view_yview+170+random_range(-1, 1),string_copy(str[text],0,i));
draw_text_colour(view_xview+30+random_range(-1.25, 1.25),view_yview+170+random_range(-1.25, 1.25),string_copy(str[text],0,i),c_red,c_red,c_red,c_red,.5);
draw_text_colour(view_xview+30+random_range(-1.25, 1.25),view_yview+170+random_range(-1.25, 1.25),string_copy(str[text],0,i),c_red,c_red,c_red,c_red,.25);
}
else
{
//yellow ghosty shaky text
if effect = 8{
draw_set_color(c_yellow);
randomize();
draw_text(view_xview+30+random_range(-1, 1),view_yview+170+random_range(-1, 1),string_copy(str[text],0,i));
draw_text_colour(view_xview+30+random_range(-1.25, 1.25),view_yview+170+random_range(-1.25, 1.25),string_copy(str[text],0,i),c_yellow,c_yellow,c_yellow,c_yellow,.5);
draw_text_colour(view_xview+30+random_range(-1.25, 1.25),view_yview+170+random_range(-1.25, 1.25),string_copy(str[text],0,i),c_yellow,c_yellow,c_yellow,c_yellow,.25);
}
else
{
if effect = 9{
draw_set_color(c_green);
draw_text(view_xview+30,view_yview+170,string_copy(str[text],0,i));
}
}
}
}
}
}
}
}
}
}
any help is appreciated, and btw the obj_testtext is its own object, and is not attached to any other object
 
C

CreatorAtNight

Guest
What exactly is the problem? And also, your code looks a bit strange and is hard to read. Try to use better indentation so it's easier to read. In the last code block you are closing all your if effect statements at the end, I don't think that's right.

Like the first if statement, I would personally like to write it like this:

Your code:
Code:
//for people who like z
if keyboard_check_pressed(ord('Z'))
{
if text=textmax{
if i=imax{
   instance_destroy();
}
}
else
{
 if text<textmax{
  if i=imax
   {
   text+=1
   i=0
   }
   }
 else
  {
  instance_destroy();
  }
 }
}
My code
Code:
//for people who like z
if(keyboard_check_pressed(ord('Z'))){
    if(text=textmax){
        if(i=imax){
            instance_destroy();
        }
    } else {
        if(text<textmax){
            if(i=imax){
                text+=1
                i=0
            }
        } else {
            instance_destroy();
        }
    }
}
This way it's also easier to keep track of your opening and closing brackets.
 
Last edited by a moderator:

EZTALES

Member
What exactly is the problem? And also, your code looks a bit strange and is hard to read. Try to use better indentation so it's easier to read. In the last code block you are closing all your if effect statements at the end, I don't think that's right.

Like the first if statement, I would personally like to write it like this:

Your code:
Code:
//for people who like z
if keyboard_check_pressed(ord('Z'))
{
if text=textmax{
if i=imax{
   instance_destroy();
}
}
else
{
 if text<textmax{
  if i=imax
   {
   text+=1
   i=0
   }
   }
 else
  {
  instance_destroy();
  }
 }
}
My code
Code:
//for people who like z
if(keyboard_check_pressed(ord('Z'))){
    if(text=textmax){
        if(i=imax){
            instance_destroy();
        }
    } else {
        if(text<textmax){
            if(i=imax){
                text+=1
                i=0
            }
        } else {
            instance_destroy();
        }
    }
}
This way it's also easier to keep track of your opening and closing brackets.
What exactly is the problem? And also, your code looks a bit strange and is hard to read. Try to use better indentation so it's easier to read. In the last code block you are closing all your if effect statements at the end, I don't think that's right.

Like the first if statement, I would personally like to write it like this:

Your code:
Code:
//for people who like z
if keyboard_check_pressed(ord('Z'))
{
if text=textmax{
if i=imax{
   instance_destroy();
}
}
else
{
 if text<textmax{
  if i=imax
   {
   text+=1
   i=0
   }
   }
 else
  {
  instance_destroy();
  }
 }
}
My code
Code:
//for people who like z
if(keyboard_check_pressed(ord('Z'))){
    if(text=textmax){
        if(i=imax){
            instance_destroy();
        }
    } else {
        if(text<textmax){
            if(i=imax){
                text+=1
                i=0
            }
        } else {
            instance_destroy();
        }
    }
}
This way it's also easier to keep track of your opening and closing brackets.
wow man, you're a lifesaver! thanks! one problem tho, when the text is done it deletes the entire object, any fix for that?
 
C

CreatorAtNight

Guest
In the part of your code that I rewrote for you, you have this part at the end:
Code:
else {
    instance_destroy();
}
That must be what destroys the object after the last text is written.
How do you want to close the text window?
 

EZTALES

Member
In the part of your code that I rewrote for you, you have this part at the end:
Code:
else {
    instance_destroy();
}
That must be what destroys the object after the last text is written.
How do you want to close the text window?
I just want it to dissapear, simple as that
 
C

CreatorAtNight

Guest
You could just add str[5]="" So it doesn't show any text at the end. Don't give up so fast! : )
 
Why do you need it to simply disappear? Also, you could literally just put an if (show_text == true) check before the drawing of the text and set it to false after all the text has been shown if you simply want it to not draw the text anymore. I'd say if you're having trouble with things this simple, you should probably work with a simpler project (I get the feeling that you're using someone elses code/example for this textbox and you don't fully understand what's going on). Trying to code blindly when you don't understand what you're coding is a recipe for disaster. So start simple and work your way up to more complex stuff.

EDIT: ...There is one simple line that has been pointed out called instance_destroy() that you have typed into your code that is destroying the instance. If you delete that code, and the code you have posted is the only place that it has an instance_destroy(), then the text won't get destroyed. Start with something simpler as it's very clear that you don't really understand what is going on with this code.
 

EZTALES

Member
Why do you need it to simply disappear? Also, you could literally just put an if (show_text == true) check before the drawing of the text and set it to false after all the text has been shown if you simply want it to not draw the text anymore. I'd say if you're having trouble with things this simple, you should probably work with a simpler project (I get the feeling that you're using someone elses code/example for this textbox and you don't fully understand what's going on). Trying to code blindly when you don't understand what you're coding is a recipe for disaster. So start simple and work your way up to more complex stuff.
thanks man, and yes i don't know whats going on! thanks for the wake up call.
 

EZTALES

Member
the main issue is i want to make a basic rpg textbox (undertale for instance) but i haven't had any luck sadly.
 
C

CreatorAtNight

Guest
UI elements can be hard to deal with. You might want to try working on an easier project first. If you really just want to make a simple RPG game you might want to check out RPG maker. It doesn't require coding knowledge and you can make pretty decent basic RPG games with it.
 
"Basic" RPG textboxes are not simple beasts at all. I mean, they are not the most complex things by far, but if you're a beginner, it's much better to start with a very simple project and work your way up. Every feature you add to a game increases it's complexity, and when you're new to coding, you want to have as little complexity as possible, so you can just start to wrap your mind around how code works at all. This is why people suggest pong clones, breakout clones, asteroids clones, etc, for a first game. These types of games have simple examples of common game mechanics that will teach you a lot about coding as you try to implement them. Scoping issues (making a game that is too big, or too complex for your current skill set) is THE single most common error that new programmers make. If you want to run, ya gotta learn how to crawl first.
 

EZTALES

Member
UI elements can be hard to deal with. You might want to try working on an easier project first. If you really just want to make a simple RPG game you might want to check out [link=[URL]https://www.rpgmakerweb.com/]RPG[/URL] maker[/link]. It doesn't require coding knowledge and you can make pretty decent basic RPG games with it.
I have tried RPG maker and made games with it, so i may do that.
 
Don't give up on GM though. The only real problem with GM is that it is marketed as very beginner friendly, but when you really get down to it, if you want to make a proper game (especially something like an RPG), it's going to be very complex to code. This is because GM will only hold your hand for the very basics. Once you move past making an instance move to a point and simple things like that, you will need to start developing a firm foundation in actual coding to get things working right. So GM is very powerful as a game creation tool, but you have to really work at learning it (in the same way you would have to really work at learning any other coding language) to achieve good results. And this means starting at the very basics and working your way up.

RPG Maker will let you make an RPG, but (unless you really know the tool inside out) the RPGs you make will be very generic and limited to exactly what RPG maker lets you do. GM is different as it gives you the basic tools to create anything but this comes with the drawback of being much harder to pick up and start toying with.
 

EZTALES

Member
Don't give up on GM though. The only real problem with GM is that it is marketed as very beginner friendly, but when you really get down to it, if you want to make a proper game (especially something like an RPG), it's going to be very complex to code. This is because GM will only hold your hand for the very basics. Once you move past making an instance move to a point and simple things like that, you will need to start developing a firm foundation in actual coding to get things working right. So GM is very powerful as a game creation tool, but you have to really work at learning it (in the same way you would have to really work at learning any other coding language) to achieve good results.
what is the best way to learn GM tho? books? online? please i would really like to know :) and i decided not to use RPG maker because i want to finish my project.
 
The best way to learn GM is to scrap the RPG project for now (not forever, just for now). Online tutorials are great, but don't just look up a tutorial for something complex (like a dialogue engine) and simply copy+paste the code. Look up "first game in GM" or something like that. As I said, a pong clone or an asteroids clone is a great starting place. You might think it is too simple and boring, but once you factor in getting a menu going, having all the game mechanics (movement, shooting, score, interactions), displaying flashy visuals, making sure there are no bugs, etc, you will end up with a project that will teach you a lot, push your boundaries and once you have finished with it, it will give you a great sense of pride to be able to boot up a fully featured game that you have created and play it. With things like an RPG, it's very easy to imagine each section and it might seem simple, but VERY quickly you will realise that there are literally thousands upon thousands of hours worth of coding that need to be poured into it to make it even run, let alone run bug free and feature complete.

So my suggestions:

1. Start very small.

2. Look up online tutorials for that very small thing. Make sure as you're going through the tutorial that you actually understand why a piece of code is being used, don't simply copy it.

3. USE THE MANUAL CONSTANTLY. This is the biggest one for new programmers. Almost every single programmer has the manual open 90% of the time. This isn't limited to beginner programmers. Keep the manual open. Whenever you run into a line of code you don't understand middle click it and it will open that code in the manual. Read the manual thoroughly for each entry. Some entries in the manual can be confusing and will require reading it multiple times as well as testing the code out in various ways to see how it actually functions. Make sure you do this, start a new project and use it just for testing lines of code that you'll delete once you understand how it works. I do this all the time with advanced functionality. Do I want to code a friendship system between NPCs and the player? I'm not going to do that immediately in my main project, I'm going to open a new project and toy around with various ways of achieving this, using the manual constantly. Once I'm happy with the system, it's easy to code it up in my main project with a lot less fuss and less of a chance of breaking things.

4. Join the GM discord and ask basic questions there, people are very friendly and questions are often answered way quicker than here on the forums (https://discord.gg/By6u9pC)

5. Don't overscope. Each additional feature you want to put in a game can extend the time you will have to spend coding by MONTHS. This is something that beginner programmers do not understand at all. Underscope rather than overscope. Make a smaller game. Always make a smaller game (even excellent programmers fall into this trap and it is probably the most common game dev refrain).

6. Have fun. It can be frustrating learning to code and the only way you will get through it is by having fun. If you're finding yourself getting extremely frustrated trying to get features working, don't be afraid to scrap the project till later and start with something smaller. The easier it is to achieve your goals in the beginning, the more fun coding will be and the more likely you will be to push through the wall of learning until you can actually execute your true dream projects.

7. This is just a general one, but make sure you understand how basic code works. This includes if statements, with() loops, for() loops, etc. Make sure you understand what are the potential uses of each statement and what is best for what scenario. The resident cat who is cold (
@FrostyCat) has a number of excellent breakdowns about these topics (things like instances vs objects, how to use statements, how to use variable flags, etc) that should actually be required reading for everyone when they first boot up GM. I'm a little too lazy to hunt down the links, but try going through their posting history or searching their name alongside "if statements" or something like that (or if your lucky, they might just pop in and link these things themselves).

8. Most of all, knuckle down and actually try to learn. When you are trying to learn code, you are actually in school. People spend many years at universities to develop the required skill sets to code properly. If you're not going to go to uni to learn, you have to come in with an educational mindset. Learning how to learn on your own is a skill that you will develop over time and one that is 100% necessary for any self-taught coder.

That's my piece for now. There's lots more advice that could be given, but this should give you something to springboard off.
 

EZTALES

Member
The best way to learn GM is to scrap the RPG project for now (not forever, just for now). Online tutorials are great, but don't just look up a tutorial for something complex (like a dialogue engine) and simply copy+paste the code. Look up "first game in GM" or something like that. As I said, a pong clone or an asteroids clone is a great starting place. You might think it is too simple and boring, but once you factor in getting a menu going, having all the game mechanics (movement, shooting, score, interactions), displaying flashy visuals, making sure there are no bugs, etc, you will end up with a project that will teach you a lot, push your boundaries and once you have finished with it, it will give you a great sense of pride to be able to boot up a fully featured game that you have created and play it. With things like an RPG, it's very easy to imagine each section and it might seem simple, but VERY quickly you will realise that there are literally thousands upon thousands of hours worth of coding that need to be poured into it to make it even run, let alone run bug free and feature complete.

So my suggestions:

1. Start very small.

2. Look up online tutorials for that very small thing. Make sure as you're going through the tutorial that you actually understand why a piece of code is being used, don't simply copy it.

3. USE THE MANUAL CONSTANTLY. This is the biggest one for new programmers. Almost every single programmer has the manual open 90% of the time. This isn't limited to beginner programmers. Keep the manual open. Whenever you run into a line of code you don't understand middle click it and it will open that code in the manual. Read the manual thoroughly for each entry. Some entries in the manual can be confusing and will require reading it multiple times as well as testing the code out in various ways to see how it actually functions. Make sure you do this, start a new project and use it just for testing lines of code that you'll delete once you understand how it works. I do this all the time with advanced functionality. Do I want to code a friendship system between NPCs and the player? I'm not going to do that immediately in my main project, I'm going to open a new project and toy around with various ways of achieving this, using the manual constantly. Once I'm happy with the system, it's easy to code it up in my main project with a lot less fuss and less of a chance of breaking things.

4. Join the GM discord and ask basic questions there, people are very friendly and questions are often answered way quicker than here on the forums (https://discord.gg/By6u9pC)

5. Don't overscope. Each additional feature you want to put in a game can extend the time you will have to spend coding by MONTHS. This is something that beginner programmers do not understand at all. Underscope rather than overscope. Make a smaller game. Always make a smaller game (even excellent programmers fall into this trap and it is probably the most common game dev refrain).

6. Have fun. It can be frustrating learning to code and the only way you will get through it is by having fun. If you're finding yourself getting extremely frustrated trying to get features working, don't be afraid to scrap the project till later and start with something smaller. The easier it is to achieve your goals in the beginning, the more fun coding will be and the more likely you will be to push through the wall of learning until you can actually execute your true dream projects.

7. This is just a general one, but make sure you understand how basic code works. This includes if statements, with() loops, for() loops, etc. Make sure you understand what are the potential uses of each statement and what is best for what scenario. The resident cat who is cold (
@FrostyCat) has a number of excellent breakdowns about these topics (things like instances vs objects, how to use statements, how to use variable flags, etc) that should actually be required reading for everyone when they first boot up GM. I'm a little too lazy to hunt down the links, but try going through their posting history or searching their name alongside "if statements" or something like that (or if your lucky, they might just pop in and link these things themselves).

8. Most of all, knuckle down and actually try to learn. When you are trying to learn code, you are actually in school. People spend many years at universities to develop the required skill sets to code properly. If you're not going to go to uni to learn, you have to come in with an educational mindset. Learning how to learn on your own is a skill that you will develop over time and one that is 100% necessary for any self-taught coder.

That's my piece for now. There's lots more advice that could be given, but this should give you something to springboard off.
thanks man, and will do! youv'e been a great help.
 
Top