Dialogue Help ~!

P

Piyo

Guest
Hello! I'm trying out a dialogue system where when the player interacts with an object, the respective dialogue pops up. Since I'm just starting out, I'd like to get the 'gist' of GML before beginning to code efficiently by using scripts/etc. ^^

My DRAW and DRAW GUI events have no problems - the main problem lies within the STEP_1 EVENT.

The first part of the STEP_1 EVENT works fine. (the 'startup' one)


But the second loop seems to contain bugs >w<
It only draws the first two characters of the string then stops.


To be more clear, this is how I see the code. Please correct me if I'm mistaken~!
(STEP_1 EVENT)


//CREATE EVENT
Code:
message[0] = "This is a sign post.";
message[1] = "Read what it says?";

startup = true;
message_current = 0;
message_end = 1;
message_draw = "";
increase = 1;
characters = 0;
hold = 0;
message_length = string_length(message[message_current]);

//STEP_1 EVENT
Code:
if (startup == true) {
    if (characters < message_length) {
        hold = keyboard_check(ord("Z"));
        characters += increase * (1 + hold);
        message_draw = string_copy(message[message_current], 0, characters);
    }
    else {startup = false;}
}

else {
    if (keyboard_check_pressed(ord("Z"))) {
        if (message_current < 1) {
            message_current += 1;
            message_length = string_length(message[message_current]);
            characters = 0;
            message_draw = "";
            if (characters < message_length) {
                hold = keyboard_check(ord("Z"));
                characters += increase * (1 + hold);
                message_draw = string_copy(message[message_current], 0, characters);
            }
            else {
                message_current = -1
                instance_destroy();
                obj_player.spd = 5;
            }
        }
    }
}

//STEP_2 EVENT (works fine)
Code:
if (message_current == 1) {
        instance_create(256,416,obj_yn);
}

if (keyboard_check_pressed(ord('X'))) {
instance_destroy();}
 

GMWolf

aka fel666
Line 12- what does the "if message_current < 1" do exactly?
It looks like you first check if its < 1, but then immediately increment it.
So first step, message_current is -1, incremented to 0.
Second step its 0, incremented to 1.
And third step, its 1. So its no longer < 1.

Here is your problem.


Btw, this is pretty good code.
 
M

Master_Wizard

Guest
When I try to run the game it works but when I attack I get a error saying




___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_player:

Variable obj_player.flase(100010, -2147483648) not set before reading it.
at gml_Script_scr_attack_state (line 24) - if (image_index >= 3 and attacked == flase) {
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scr_attack_state (line 24)
called from - gml_Object_obj_player_StepNormalEvent_1 (line 2) - script_execute(state);



Can anyone help me?
 
P

Piyo

Guest
Line 12- what does the "if message_current < 1" do exactly?
It looks like you first check if its < 1, but then immediately increment it.
So first step, message_current is -1, incremented to 0.
Second step its 0, incremented to 1.
And third step, its 1. So its no longer < 1.

Here is your problem.


Btw, this is pretty good code.
When the player first presses 'Z', the first loop draws message[0] and message_current = 0.
After pressing 'Z' again, message[1], should be drawn. The program checks if "message_current < 1" (0 <1)
If so, it increments message_current by 1 so message_current = 0+1 = 1.
And message[message_current] which is message[1] is drawn.

The only trouble I get is the loop inside the second loop >w<
I read it fine, but I'm not sure if GMS reads it like I do.


Ah, I got this versatile code from here ~
 
Top