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.
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.Hard to say without code. Why do you have 5 variables to handle movement? What is the difference between them?
TEXT1:Hard to say without code. Why do you have 5 variables to handle movement? What is the difference between them?
Oh, sorry. Here's the character code too.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. 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.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"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.
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".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"
Oh, alright let me try that.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.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".
is that enough or do you want more?Please provide code snippets whenever you make large edits to your code to reflect said changes.
if active == true {
global.moving = false
}
else {
global.moving = true
}
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.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
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.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.
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.
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 agoYes, 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.
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.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.
k.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.