Windows [SOLVED] "unable to convert string to int64" error

E

E.M.I

Guest
Hi! So for a while I've been making a dialogue system for my game. I left it in a pretty barebones but working state a month or so ago, and now I wanted to add some more sprites and visual polishes to it so I started to work on it again. However, whenever I try to print two different options for the player to choose from (which worked perfectly before) I get the "unable to convert string to int64" error.

I've researched what it means, and I'm not trying to turn the option strings into ints, definitely not using the int64() constructor. It might matter than I got a new PC a little while ago and haven't touched the dialogue system since, and the project transitioned from Mac to Windows because of the change.

This is going to be a lot of pretty messy code, as I'm not sure what part of it is causing the error. I'll try to comment it as thoroughly as I can, but yeah, thanks in advance.

Create event of my player object:
Code:
// Creates arrays for the regular dialogue and the options given
dialogue[0, 0] = "Hey there!";
dialogue[0, 1] = portrait.normal;
dialogue[0, 2] = dialogue_type.normal;
dialogue[1, 0] = "/2How's it going?";
dialogue[1, 1] = portrait.normal;
dialogue[1, 2] = dialogue_type.choice;
dialogue[2, 0] = "/3I'm glad!";
dialogue[2, 1] = portrait.normal;
dialogue[2, 2] = dialogue_type.response;
dialogue[3, 0] = "/1Hope it gets better!";
dialogue[3, 1] = portrait.normal;
dialogue[3, 2] = dialogue_type.response;

choice[1, 0] = "> Pretty good!";
choice[1, 1] = "> Not that good...";
Step event of my player object:
Code:
// Triggers dialogue script when the z_key is pressed
if (z_key_once and !instance_exists(obj_dialogue))
    scr_dialogue(dialogue, choice);
Dialogue script scr_dialogue:
Code:
var text = argument0
var choice = argument1;

// Creates the dialogue object
var dialogueObject = instance_create_layer(0, 0, "Instances", obj_dialogue);

// Adds dialogue to the respective arrays in the dialogue object
for (i = 0; i < array_height_2d(text); i++)
{
    dialogueObject.message[i, 0] = text[i, 0];
    dialogueObject.message[i, 1] = text[i, 1];
    dialogueObject.message[i, 2] = text[i, 2];
 
    if (text[i, 2] == dialogue_type.choice)
    {
        for(t = 0; t < array_length_2d(choice, i); t++)
            dialogueObject.choice[i, t] = choice[i, t];
    }
}
Dialogue object's Create event:
Code:
/// @description insert description here

message[0, 0] = " ";

choice[0, 0] = " ";

currentMessage = 0;
choice = false;
messageEnd = 0;
timer = 0;
charsDrawn = 0;

spritePortrait = 0;
modifier = 0;
tDescends = false;

t = 0;
moveRange = 5;
moveSpeed = 2.5;

textPosX = 0;
textPosY = 0;

printChoice = false;
printAnswer = false;
chosenAnswer = 0;
choiceNumber = 0;
responseSkip = 0;
Dialogue object's Draw event:
Code:
/// @description Insert description here

scr_get_input();

draw_set_font(fnt_1);

messageEnd = array_height_2d(message);

if (t >= 215 or tDescends)
{
    tDescends = true;
    t--;
 
    if (t == 0)
    {
        t++;
        tDescends = false;
    }
}

else t++;

// If there's any messages to print
if (messageEnd > 0)
{
    var charWidth = 20;
    var lineEnd = 42;
    var line = 0;
    var charCount = 0;
    var currentChar = 1;
    var delay = 1.5;
 
    if (charsDrawn < string_length(message[currentMessage, 0]))
    {
        if (timer >= delay)
        {
            charsDrawn++;
            timer = 0;
        }
    
        else timer++;
    }
 
    // The position the text is drawn at
    if (spritePortrait == 0)
        textPosX = 5;
    
    else textPosX = 270;
    
    textPosY = 505;
 
    // If the current message exists
    if (currentMessage < messageEnd)
    {
        draw_sprite(spr_dialogue_box, image_index, 240, 480);
        global.pausedType = pauseType.dialogue;
    
        while (currentChar <= string_length(message[currentMessage, 0]) and currentChar <= charsDrawn)
        {
            var length = 0;
    
            while (string_char_at(message[currentMessage, 0], currentChar) != " " and currentChar <= string_length(message[currentMessage, 0]))
            {
                currentChar++;
                length++
            }
    
            if (charCount + length > lineEnd)
            {
                charCount = 0;
                line++;
            }
    
            currentChar -= length;

            if (message[currentMessage, 2] != dialogue_type.choice)
            {
                if (z_key_once and currentMessage <= messageEnd - 1)
                {
                    currentMessage++;
                    charsDrawn = 0;
                }
            
                if (z_key_once and currentMessage >= messageEnd - 1)
                {
                    global.pausedType = 0;
                    instance_destroy(id, true);
                    message[currentMessage, 2] = 0;
                }
            }
                
            // Sets modifiers
            if (string_char_at(message[currentMessage, 0], currentChar) == "/")
            {
                modifier = string_char_at(message[currentMessage, 0], ++currentChar);
                currentChar++;
            }
        
            switch(modifier)
            {
        
                //Normal text
                case 0:
                {
                    draw_set_colour(c_black);
                    draw_text(textPosX + (charCount*charWidth), textPosY + (40 * line), string_char_at(message[currentMessage, 0], currentChar));
                    break;
                }
 
                // Shaky text
                case 1:
                {
                    draw_set_colour(c_black);
                    draw_text(textPosX + (charCount*charWidth) + random_range(-2, 2), textPosY + (40 * line) + random_range(-2, 2), string_char_at(message[currentMessage, 0], currentChar));
                    break;
                }
        
                // Wavy text
                case 2:
                {
                    draw_set_colour(c_black);
                    var so = t + currentChar;
                    var shift = sin(so * pi * moveSpeed/room_speed) * moveRange;
                    draw_text(textPosX + (charCount*charWidth), textPosY + (40 * line) + shift, string_char_at(message[currentMessage, 0], currentChar));
                    break;
                }
        
                // Color shift effect
                case 3:
                {
                    var col1 = make_color_hsv(t, 255, 255);
                    var col2 = make_color_hsv(t + 75, 255, 255);
                    draw_text_color(textPosX + (charCount*charWidth), textPosY + (40 * line), string_char_at(message[currentMessage, 0], currentChar), col1, col1, col2, col2, 1);
                    break;
                }
            }
            
            // If there are dialogue choices
            if (message[currentMessage, 2] == dialogue_type.choice)
            {
                // If the question is done printing and hasn't been answered
                if (currentChar >= string_length(message[currentMessage, 0]) and !printAnswer)
                    printChoice = true;
            
                // If it's time for the choices to print
                if (printChoice)
                {   
                    var choiceColor1;
                    var choiceColor2;
                
                    // If the player presses W, the cursor goes up; if they press S, it goes down
                    if (w_key_once)
                    {
                        choiceNumber--;
                        w_key_once = false;
                    }
                
                    else if (s_key_once)
                    {
                        choiceNumber++;
                        s_key_once = false;
                    }
                
                    // Loops the cursor back around
                    if (choiceNumber < 0) choiceNumber = 1;
                
                    else if (choiceNumber > 1) choiceNumber = 0;
                
                    // Sets the correct color according to the cursor's position
                    switch (array_length_2d(choice, currentMessage))
                    {       
                        case 2:
                        switch (choiceNumber)
                        {
                            case 0:
                            choiceColor1 = c_yellow;
                            choiceColor2 = c_black;
                            chosenAnswer = 0;
                        
                            if (z_key_once and currentMessage < messageEnd - 1)
                            {
                                responseSkip = array_length_2d(choice, currentMessage) - 1;
                                printAnswer = true;
                                printChoice = false;
                                charsDrawn = 0;
                            }
                        
                            break;
                        
                            case 1:
                            choiceColor1 = c_black;
                            choiceColor2 = c_yellow;
                            chosenAnswer = 1;
                        
                            if (z_key_once and currentMessage < messageEnd - 1)
                            {
                            
                                responseSkip = array_length_2d(choice, currentMessage);
                                printAnswer = true;
                                printChoice = false;
                                charsDrawn = 0;
                            }
                        
                            break;
                        }
                    
                        currentMessage += responseSkip;
                        break;
                    }
                
                    if (!printAnswer)
                    {
                        draw_text_color(textPosX, textPosY + (40 * (line + 1)), choice[currentMessage, 0], choiceColor1, choiceColor1, choiceColor1, choiceColor1, 1);
                        draw_text_color(textPosX, textPosY + (40 * (line + 2)), choice[currentMessage, 1], choiceColor2, choiceColor2, choiceColor2, choiceColor2, 1);
                    
                        draw_text_color(textPosX - 15, choice[currentMessage, chosenAnswer].y, c_yellow, ">", c_yellow, c_yellow, c_yellow, 1);
                    }
                    
                    else break;
                }
                }
            
            charCount++;
            currentChar++;
        }
    
        // Changing the portrait sprite
    
        spritePortrait = message[currentMessage, 1];
    
        switch(spritePortrait)
        {
            case portrait.normal: draw_sprite(spr_eitim_portrait_normal, 0, -10, 453); break;
            case portrait.happy: draw_sprite(spr_eitim_portrait_happy, 0, -10, 453); break;
            case portrait.sad: draw_sprite(spr_eitim_portrait_sad, 0, -10, 453); break;
        }
    }
}
I'm aware the code is quite messy, but one of the reasons I came back to it was to make it more efficient and readable, though I gotta get it working first. Still, any suggestions on how to do so are also appreciated! Sorry for the trouble, and again, thanks a lot!
- Emi
 
Last edited by a moderator:

TailBit

Member
Where in all the code does it trigger the error? Post the rest of the error message?

And try to click the broom icon to clean the resorces cache, if it gets corrupt then odd things can happen.
 
Last edited:

Azenris

Member
is it that
Code:
modifier = string_char_at(message[currentMessage, 0], ++currentChar);
return a string/char, then in switch(modifier) you compare it to ints.?
 
E

E.M.I

Guest
Where in all the code does it trigger the error? Post the rest of the error message?

And try to click the broom icon to clean the resorces cache, if it gets corrupt then odd things can happen.
Oh you're right, sorry. The error message is:
Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object obj_dialogue:

unable to convert string "> Pretty good!" to int64
 at gml_Object_obj_dialogue_Draw_64 (line 216) -                                           draw_text_color(textPosX - 15, choice[currentMessage, chosenAnswer].y, c_yellow, ">", c_yellow, c_yellow, c_yellow, 1);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_dialogue_Draw_64 (line 216)
It only happens when the choices are drawn, I've tested it and the normal dialogue that goes first is drawn without a problem.
And I tried cleaning the resources cache and nothing changed, so yeah.
 
E

E.M.I

Guest
is it that
Code:
modifier = string_char_at(message[currentMessage, 0], ++currentChar);
return a string/char, then in switch(modifier) you compare it to ints.?
is it that
Code:
modifier = string_char_at(message[currentMessage, 0], ++currentChar);
return a string/char, then in switch(modifier) you compare it to ints.?
It's definitely not that, it only converts the / and the number at the beginning of messages. I tried adding a modifier to the first line of dialogue (which is drawn as it should without any errors) and it worked without any error popping up.
 

chamaeleon

Member
Oh you're right, sorry. The error message is:
Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object obj_dialogue:

unable to convert string "> Pretty good!" to int64
 at gml_Object_obj_dialogue_Draw_64 (line 216) -                                           draw_text_color(textPosX - 15, choice[currentMessage, chosenAnswer].y, c_yellow, ">", c_yellow, c_yellow, c_yellow, 1);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_dialogue_Draw_64 (line 216)
It only happens when the choices are drawn, I've tested it and the normal dialogue that goes first is drawn without a problem.
And I tried cleaning the resources cache and nothing changed, so yeah.
Your choice 2d array contains strings, yes? Strings do not have x and y coordinates. Instances do..
 
E

E.M.I

Guest
Your choice 2d array contains strings, yes? Strings do not have x and y coordinates. Instances do..
But what I'm doing is drawing the text at that position. The variables I use for the coordinates, textPosX and textPosY, are already set.
 
Oh you're right, sorry. The error message is:
Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object obj_dialogue:

unable to convert string "> Pretty good!" to int64
 at gml_Object_obj_dialogue_Draw_64 (line 216) -                                           draw_text_color(textPosX - 15, choice[currentMessage, chosenAnswer].y, c_yellow, ">", c_yellow, c_yellow, c_yellow, 1);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_dialogue_Draw_64 (line 216)
It only happens when the choices are drawn, I've tested it and the normal dialogue that goes first is drawn without a problem.
And I tried cleaning the resources cache and nothing changed, so yeah.
Please show us the event where the error occurs: the Draw (or draw gui) of the obj_dialogue. That is the only event you omitted.
 
E

E.M.I

Guest
Please show us the event where the error occurs: the Draw (or draw gui) of the obj_dialogue. That is the only event you omitted.
Oh god, how dumb can I get? What I said is obj_dialogue's Step event is actually the Draw event. Really sorry for the confusion!
 

SeraphSword

Member
In your draw_text_color, the second argument is to get your y value of where to draw it. You are trying to get the y value of your array called "choice" there.
 
E

E.M.I

Guest
In your draw_text_color, the second argument is to get your y value of where to draw it. You are trying to get the y value of your array called "choice" there.
I... don't know what you mean. For the second argument of draw_text color, I use "textPosY + (40 * (line + 1))" or + 2, which is an int. I printed it with show_debug_message and the result was 545. I'm giving it a coordinate to draw the text at. Am I not understanding something here?
 

SeraphSword

Member
In the error message:
Code:
draw_text_color(textPosX - 15, choice[currentMessage, chosenAnswer].y,
Line 216 of the Draw event for obj_dialogue.
 
E

E.M.I

Guest
In the error message:
Code:
draw_text_color(textPosX - 15, choice[currentMessage, chosenAnswer].y,
Line 216 of the Draw event for obj_dialogue.
Ooooooh shoot, I thought you meant the lines above! Changed it and it worked, that was the problem. Thank you so much!
 
You have left your switch and case statements open to a logic error, by not including "default:" after your case statements in each switch branch.

switch ( x )
{
case 1 : /* do this */
break;

case 2 : /* do that */
break;
....
....
default : /*do this when all other cases fail */

}

Its a very bad practice to leave out default, even if you do not have a condition for default. The default: is something you should consider in your code when your using switch.
 
Last edited:
Top