Legacy GM Movement while in textbox bug.

F

Frisk2401

Guest
Okay so there is a variable that controls when the player can move, but I also have four other variables that control it, is there a way to make them not conflict each other? I can provide code if needed.
 
A

Annoyed Grunt

Guest
Hard to say without code. Why do you have 5 variables to handle movement? What is the difference between them?
 
F

Frisk2401

Guest
Hard to say without code. Why do you have 5 variables to handle movement? What is the difference between them?
The 4 variables are because of the text being re-used. Basically.. When you toggle the first one, the second one says the same thing, ect.
 
F

Frisk2401

Guest
Hard to say without code. Why do you have 5 variables to handle movement? What is the difference between them?
TEXT1:
Create:
global.moving =false
global.active = false
message[0] = "* My closet, doesn't really have a use since I don't wear most of them."
message_current = 0 //0 is the first number in our list of messages
message_end = 0 //how many messages you want
message_draw = ""; //this is what we 'write' out.
increase = 0.7 //the speed at which new characters are added
characters = 0 //how many characters have been drawn
hold = 999999999999999999999999999 //if we hold 'Z', the text will render faster

message_len

Step:
if global.active = true{
if (characters < message_length) {
hold = keyboard_check(ord('X'))
characters += increase * (1 + hold)
message_draw = string_copy(message[message_current], 0, characters)
}
else{
if(keyboard_check_pressed(ord('z'))){
if(message_current < message_end){
message_current += 1
message_length = string_length(message[message_current])
characters = 0
message_draw = "";
}
}
}
}
if global.active = true{
global.moving = true
}
else{
global.moving = false
}

Interact With Object:
if(keyboard_check_pressed(ord('Z'))) {
global.active = !global.active;
}

Draw:

if global.active = true{
global.canmove=false
draw_set_font(fnt)
draw_set_color(c_black);
draw_rectangle(32,512,992,736,0);
draw_set_color(c_white);
draw_rectangle(37,516,988,732,0);
draw_set_color(c_black);
draw_rectangle(43,522,982,726,0);
draw_set_color(c_white);
draw_text_ext(70,535,message_draw, 60,900)
}
else{
global.canmove = true
}

The other ones are the same but replace global.active with global.active2, global.active3 and global.active4
 
A

Annoyed Grunt

Guest
global.moving doesn't seem to do anything, why is it there?
If each text instance needs an "active" variable then global.active should not be, well, global. Each instance should have its own "active" instance variable. You can read more about variable scoping here.
 
F

Frisk2401

Guest
global.moving doesn't seem to do anything, why is it there?
If each text instance needs an "active" variable then global.active should not be, well, global. Each instance should have its own "active" instance variable. You can read more about variable scoping here.
Oh, sorry. Here's the character code too.

Chara:

Create:
friction=0.9
global.canmove=true
p_speed = 5

Step:
image_speed = speed/40
//this one works, but could be slower.

if speed=0 image_index = 0
if global.active = false{
global.canmove=true
}
if global.active2 = false{
global.canmove=true
}
if global.active4 = false{
global.canmove=true
}
if global.active3 = false{
global.canmove=true
}



if global.canmove=true{
var dx = keyboard_check(vk_right)-keyboard_check(vk_left);
var dy = keyboard_check(vk_down)-keyboard_check(vk_up);
if (dx != 0 || dy != 0) {
direction = point_direction(0, 0, dx, dy);
speed = 7;
} else {
speed = 0;
}
}

Left Key:
if global.canmove=true
{
direction=180
sprite_index=spr_chara_left
}

Up Key:
if global.canmove=true
{
direction=90
sprite_index=spr_chara_up
}

You get the idea of the keys.
 
A

Annoyed Grunt

Guest
global.moving still doesn't seem to do anything so there is that.
As for the rest, you haven't got in the right frame of mind yet. The player should not handle setting global.canmove, it's a variable that exists specifically for other instances to manipulate. You can think of it as a lock. Each text instance should have its own "active" instance variable. When a text instance is active, global.canmove (the lock) should be closed, and while it is not, it should be open.
You should also remove the setting of the direction variable from your key events, that's probably gonna mess up your 8-way movement system.
 
F

Frisk2401

Guest
global.moving still doesn't seem to do anything so there is that.
As for the rest, you haven't got in the right frame of mind yet. The player should not handle setting global.canmove, it's a variable that exists specifically for other instances to manipulate. You can think of it as a lock. Each text instance should have its own "active" instance variable. When a text instance is active, global.canmove (the lock) should be closed, and while it is not, it should be open.
You should also remove the setting of the direction variable from your key events, that's probably gonna mess up your 8-way movement system.
Oh. I didn't realize that global.moving didn't do anything- I'm just tired.. The global.canmove determines whether the move code works. So.. I'm not sure what you mean by that? And the 8-way works okay.
 
F

Frisk2401

Guest
global.moving still doesn't seem to do anything so there is that.
As for the rest, you haven't got in the right frame of mind yet. The player should not handle setting global.canmove, it's a variable that exists specifically for other instances to manipulate. You can think of it as a lock. Each text instance should have its own "active" instance variable. When a text instance is active, global.canmove (the lock) should be closed, and while it is not, it should be open.
You should also remove the setting of the direction variable from your key events, that's probably gonna mess up your 8-way movement system.
And you know.. It does say that there are global.active codes for each. "The other ones are the same but replace global.active with global.active2, global.active3 and global.active4"
 
F

Frisk2401

Guest
Sorry if you respond and I don't for a while, I'm gonna head to bed now.
 
A

Annoyed Grunt

Guest
And you know.. It does say that there are global.active codes for each. "The other ones are the same but replace global.active with global.active2, global.active3 and global.active4"
I understood that, I am saying that there is no reason for those variables to be global. A global variable, as explained in the link I sent you, is a variable that is supposed to be accessed by all instances. If a variable describes a single instance, then that variable should be made an instance variable. You should replace global.active, global.active2, global.active3 and global.active4 with a single "active" variable that is declared in the create event of the text object, this way each of the four text instances will have its own copy of "active".
 
F

Frisk2401

Guest
I understood that, I am saying that there is no reason for those variables to be global. A global variable, as explained in the link I sent you, is a variable that is supposed to be accessed by all instances. If a variable describes a single instance, then that variable should be made an instance variable. You should replace global.active, global.active2, global.active3 and global.active4 with a single "active" variable that is declared in the create event of the text object, this way each of the four text instances will have its own copy of "active".
Oh, alright let me try that.
 
F

Frisk2401

Guest
I understood that, I am saying that there is no reason for those variables to be global. A global variable, as explained in the link I sent you, is a variable that is supposed to be accessed by all instances. If a variable describes a single instance, then that variable should be made an instance variable. You should replace global.active, global.active2, global.active3 and global.active4 with a single "active" variable that is declared in the create event of the text object, this way each of the four text instances will have its own copy of "active".
Ooh! It works but now I can walk while in the second, third and fourth text box. The first doesn't let me walk still.
 
A

Annoyed Grunt

Guest
Please provide code snippets whenever you make large edits to your code to reflect said changes.
 
A

Annoyed Grunt

Guest
I think the issue here may have something to do with the order of the step events. In each text step event, global.moving is set to either true or false, so depending on the order (which texts are executed first and if the step event of the player is executed before, after, or in the middle of those of the texts's).
I would suggest you reset global.moving to false in the end step event of the player, and only bother to turn it on in the begin step event of the currently active step event.
However, I think a more pressing issue right now is that your code is a mess and I urge you to clean it up. While it may not seem like a big deal, having clean, well-organized code helps you identify issues faster and reduces space for human error and distraction.

  • You currently have global.moving and global.canmove. Previously you used global.canmove and global.moving was unused, now you use global.moving and it seems (?) global.canmove is unused. Pick one, delete the other.
  • Use tab inside of code blocks. Having everything to the extreme left of the code text editor makes it cluttered and hard to figure out where if statements begin and where they end.
  • You update self.active both in the step event and in the draw event. You should not do the same thing twice unless necessary for some reason or another. Furthermore, unless it has to do with drawing something, code should go in the step event. As I said above, you should scrap the way you currently do it and move it to the begin step event anyway, but it holds true for future occasions.
  • There is no need to have four different text objects that do all the same thing, with the same code. Create one base text event with the logic for drawing, and make it the parent of the singular text objects you need, and in the create event of the children objects, call event_inherited() and set the different dialogue. This will help IMMENSELY because you will have to only edit 1 text object to have the changes reflect its changes on all text objects in your game. What if you had a full game with hundreds of different dialogues and all of a sudden you wanted to change one detail? Would you go and change by hand hundreds of text objects? As you can see the way you do things currently is not feasible in the long run. The concept of parenting objects is a bit tricky for a beginner so I suggest you study the documentation on the subject.
  • Right now you do this:
Code:
if active == true {
     global.moving = false
}
else {
     global.moving = true
}
Generally speaking, if you have two variables where one needs to be the opposite of the other, you can do that directly:
Code:
global.moving = !active
 
F

Frisk2401

Guest
I think the issue here may have something to do with the order of the step events. In each text step event, global.moving is set to either true or false, so depending on the order (which texts are executed first and if the step event of the player is executed before, after, or in the middle of those of the texts's).
I would suggest you reset global.moving to false in the end step event of the player, and only bother to turn it on in the begin step event of the currently active step event.
However, I think a more pressing issue right now is that your code is a mess and I urge you to clean it up. While it may not seem like a big deal, having clean, well-organized code helps you identify issues faster and reduces space for human error and distraction.

  • You currently have global.moving and global.canmove. Previously you used global.canmove and global.moving was unused, now you use global.moving and it seems (?) global.canmove is unused. Pick one, delete the other.
  • Use tab inside of code blocks. Having everything to the extreme left of the code text editor makes it cluttered and hard to figure out where if statements begin and where they end.
  • You update self.active both in the step event and in the draw event. You should not do the same thing twice unless necessary for some reason or another. Furthermore, unless it has to do with drawing something, code should go in the step event. As I said above, you should scrap the way you currently do it and move it to the begin step event anyway, but it holds true for future occasions.
  • There is no need to have four different text objects that do all the same thing, with the same code. Create one base text event with the logic for drawing, and make it the parent of the singular text objects you need, and in the create event of the children objects, call event_inherited() and set the different dialogue. This will help IMMENSELY because you will have to only edit 1 text object to have the changes reflect its changes on all text objects in your game. What if you had a full game with hundreds of different dialogues and all of a sudden you wanted to change one detail? Would you go and change by hand hundreds of text objects? As you can see the way you do things currently is not feasible in the long run. The concept of parenting objects is a bit tricky for a beginner so I suggest you study the documentation on the subject.
  • Right now you do this:
Code:
if active == true {
     global.moving = false
}
else {
     global.moving = true
}
Generally speaking, if you have two variables where one needs to be the opposite of the other, you can do that directly:
Code:
global.moving = !active
Okay, global.canmove is gone. I understand the parent and child I think. So if the parent has a certain code event, the child will inherit? And I can call the text from the parent..? With the cleaning up thing, I'll try to do that now.
 
A

Annoyed Grunt

Guest
Okay, global.canmove is gone. I understand the parent and child I think. So if the parent has a certain code event, the child will inherit? And I can call the text from the parent..? With the cleaning up thing, I'll try to do that now.
Yes, since the code only cares about the "message" array, you can create another object, set its parent to your "obj_text_parent", and then do something like the create event.

Code:
event_inherited() //This will do everything that is in the create event of the parent, so it will create the message, message_current, message_end, etc etc variables
message[0] = "Part one of the message";
message[1] = "Part two of the message";
...
message_length = string_length(message[message_current]) //I am not sure if this is necessary as I don't know if message_length is recalculated anywhere else.
What is your issue currently? Also, could you link me the tutorial/resource you followed to create this message system? I'm curious of its origin.
 
F

Frisk2401

Guest
Yes, since the code only cares about the "message" array, you can create another object, set its parent to your "obj_text_parent", and then do something like the create event.

Code:
event_inherited() //This will do everything that is in the create event of the parent, so it will create the message, message_current, message_end, etc etc variables
message[0] = "Part one of the message";
message[1] = "Part two of the message";
...
message_length = string_length(message[message_current]) //I am not sure if this is necessary as I don't know if message_length is recalculated anywhere else.
What is your issue currently? Also, could you link me the tutorial/resource you followed to create this message system? I'm curious of its origin.
i can move while in the text box, only the second one, the third and fourth. not the first, tho. and I can't. i got that a long time ago
 
F

Frisk2401

Guest
Also I don't understand what you want me to do- Please could you repeat it but like.. Easier to understand for me, I'm dumb
 
F

Frisk2401

Guest
And I'd prefer the system where I can edit one by one. The parent thing seems a bit advanced for me.
I just really want the text system to pop up when activated, the character stops. When it's closed the character can move. But be able to have multiple in the same room without saying the same thing and not allow the character to move when the second one and third one was active..
 
F

Frisk2401

Guest
Nevermind. I got that working.. But now the player only freezes when both are active. I can walk when using one of them, then if i activate the other one at the same time, THEN I freeze. and vice versa.
 

rIKmAN

Member
Instead of making multiple posts in a row one after the other in a short space of time (this is called 'thread bumping' and is against forum rules) you can click the "EDIT" button on your existing post and add any new information or progress you've while you wait for a reply.

You should also try to post code in code boxes rather than in screenshots to make it easier for people to read and help with any issues. You can do this by using the toolbar above the reply window, clicking Insert > Code and then pasting your code into the code window.
 
F

Frisk2401

Guest
Instead of making multiple posts in a row one after the other in a short space of time (this is called 'thread bumping' and is against forum rules) you can click the "EDIT" button on your existing post and add any new information or progress you've while you wait for a reply.

You should also try to post code in code boxes rather than in screenshots to make it easier for people to read and help with any issues. You can do this by using the toolbar above the reply window, clicking Insert > Code and then pasting your code into the code window.
k.
 
Top