• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[Solved] Simple typewriter text for item pickup

I'm starting from the basics in trying to make an item pickup dialogue system. What I mean by this is that when the player interacts with an object, instead of just picking it up, the game tells you what the object is and asks if you want to pick it up. If you pick yes, then it says you picked it up and then the item is destroyed (placed in inventory). If no, the dialogue closes out and you resume what you were doing.

I have an item object that collides with the player object....

Create event of obj_item:
Code:
choice[0]="This is an item.\nTake it?"
choice[1]="You took the item."

count = 0; //keep track of choice display
text_to_write = ""; //changes based on choice array
typewriter_out = ""; //string to write
i = 1; //start position
Collision with obj_player:
Code:
if keyboard_check_pressed(vk_space)&& count == 0{
    global.freeze = true;
    count = 1;
    alarm[0]=1;
}
if count == 1{
    text_to_write = choice[0];
    instance_create_depth(50,100,-100,obj_itembox);
}

if count == 2{
    text_to_write = choice[1];
}
Alarm 0 of obj_item:
Code:
typewriter_out += string_char_at(text_to_write,i);//add new character to string
i += 1;
if (i - 1) != string_length(text_to_write){//text has not finished displaying
    alarm[0]=2; //restart alarm
}
And draw event of obj_item:
Code:
switch (count){
    case 0:
    draw_self();
    break;
    
    case 1:
    draw_self();
    draw_set_color(c_red);
    draw_text(50,50,typewriter_out);
    break;

    case 2:
        draw_set_color(c_red);
        draw_text(50,50,typewriter_out);
        break;
}
Then I have the obj_choice that appears if count == 1.

Step Event of the obj_choice:
Code:
if keyboard_check_pressed(ord("D")){ //no is highlighted
    image_index = 1;
}
if keyboard_check_pressed(ord("A")){ //yes is highlighted
    image_index = 0;
}

switch(image_index){
    case 0:
        if keyboard_check_pressed(vk_space){
            obj_item.count = 2;
            instance_destroy(self);
        }
        break;
    case 1:
        if keyboard_check_pressed(vk_space){
            obj_item.count = 0;
            obj_item.i = 1;
            obj_item.text_to_write = "";
            obj_item.typewriter_out = "";
            global.freeze = false; //the player can move again
            instance_destroy(self);
        }
        break;
}
Now, upon testing, some of this works, and some of it doesn't. If I interact with the obj_item for the first time, then choice[0] displays correctly, in typewriter format. The choice (yes/no) pops up, and if I pick no, the dialogue closes and the player can resume what they were doing. If I return to the item again, the text resets typewriter style.

What isn't working:
-Selecting yes makes the item disappear, but choice[0] continues to display rather than resetting the typewriter and then playing choice[1].
-Before I implemented the typewriter effect, there was also an issue where choice[1] WOULD display correctly, but it wouldn't destroy the object if I pressed space.

Any assistance?
 
Top