1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GML [Solved] A script doesn't recognise a sent string as a string

Discussion in 'Programming' started by XirmiX, Jul 28, 2017.

  1. XirmiX

    XirmiX Member

    Joined:
    Jul 18, 2016
    Posts:
    365
    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of Step Event0
    for object obj_textbox:

    file_exists argument 1 incorrect type (0) expecting a String (YYGS)
    at gml_Script_scr_register_handling (line 11) - else if file_exists(user_name)
    ############################################################################################
    --------------------------------------------------------------------------------------------
    stack frame is
    gml_Script_scr_register_handling (line 11)
    called from - gml_Object_obj_textbox_StepNormalEvent_1 (line 16) - scr_register_handling(noone, noone, txt);

    Essentially, you type in a string of characters in text boxes. There are two variables being used, both of which are, at the beginning, declared as strings. At the end of it all, only one of them gets sent off to a script, but even then, both are strings, always were, always will be. Yet, for some reason, this script doesn't recognise them as strings. Why?! Here's relevant code:

    Textbox creation code:
    Code:
    self.selected = false;
    self.max_char = 30;
    self.char_written = 0;
    txt = "";
    tt = "";
    
    enter_string = 0;
    
    leftX = x - (sprite_width/2);
    topY = y - (sprite_width/2);
    rightX = x + (sprite_width/2);
    bottomY = y + (sprite_height/2);
    
    Textbox draw event code:
    Code:
    draw_self();
    draw_set_colour(c_lime);
    //draw_text(x-56, y, txt);
    
    if self.selected == true
    {
        tt = keyboard_string;//set keyboard string to a temp var
        //make sure it doesnt go over the desired length
        if (string_length(tt) > 30)
        {
            //if it does go over we set it back to the correct length
            keyboard_string = string_copy(tt, 1, 30);
            txt = tt;
        }
        //these are just to update text variable (this is the variable to hold the key string value)
        var update_keys = keyboard_check_pressed(vk_backspace) || keyboard_check_pressed(vk_enter);
        if (update_keys)
        {
            txt = tt;
        }
        txt = tt;
        draw_text(x-56, y, tt);//draw the text
    }
    else
    {
        draw_text(x-56, y, txt);//this is the text when not selected
    }
    
    Textbox step event code:
    Code:
    ///Checking instance id for sending text where needed
    {
    if keyboard_check(vk_enter)
    {
        switch(self.enter_string)
        {
            case 1: //username register
                scr_register_handling(txt);
            break;
            case 2: //password register
                scr_register_handling(noone, txt);
            break;
            case 3: //password confirmation
                scr_register_handling(noone, noone, txt);
            break;
            case 4: //username login
                scr_login_handling(txt);
                obj_dataholder.logged_username = txt;
            break;
            case 5: //password login
                scr_login_handling(noone, txt);
            break;
        }
    }
    }
    
    Script code:
    Code:
    //Sets the three registration values as arguments
    {
    user_name = argument[0];
    pass_word = argument[1];
    pass_word_confirm = argument[2];
    
    if (user_name == "")
    {
        scr_message_display("Please enter a username")
    }
    else if file_exists(user_name)
    {
        scr_message_display("Username has already been taken by someone using your machine");
    }
    else
    {
        if (pass_word != pass_word_confirm)
        {
            scr_message_display("Confirmation password does not match the password you entered")
        }
        else
        {
            //irrelevant code, not showing this :P
        }
    }
    }
    

    Then for the three textbox instances that are in the room, they have the variable "enter_string" (declared in create event code) set to 1, 2 and 3 respectively, and I checked!

    My only guess would be that it has something to do with the fact that the text is written in a draw event and not a step event... But even then, the variables are declared as strings in create event, so what the hell?
     
  2. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    994
    This is a rather incoherently described problem, and I see no evidence of you attempting to display, using show_debug_message() or show_message(), the value of variables to prove to yourself that things are correct at various points in time in your code. Then there are things like the fact that you initialize enter_string to 0, but 0 does not have a case in step event switch, nor any change to its value in any of the code. So just based on what you're showing, nothing should happen at all. Finally, it rubs me the wrong way to do anything in the draw event that isn't related to drawing, like changing the values of your string variables, something more suited to step event code.
     
    Wraithious likes this.
  3. XirmiX

    XirmiX Member

    Joined:
    Jul 18, 2016
    Posts:
    365
    Alright, good point... still, nothing being clarified, however (I put show_debug_message to be shown upon the creation of textboxes, the sending of information to the script from textboxes (step event) and within the script itself, right after it receives them) and according to the debugger, everything should work fine, yet the error message still displays for whatever reason:
    upload_2017-7-28_23-57-22.png

    Line 5 of the Step event code I already provided:
    Code:
    switch(self.enter_string)
    
    -.-

    I even thought it might be that it needs to put "self." before it sends each thing, but considering that text was writing in each of the textboxes just fine and they weren't overriding each other without "self." being put behind the "txt" and "tt" variables, this couldn't have been the issue... and it wasn't:
    upload_2017-7-28_23-57-53.png

    There's no way that's the issue, however, since the strings are written to, and are even declared in CREATE event. The script should then, at least recognise them as strings, even if they're recognised as empty, but here, it's not recognising them as anything at all, or something else may be for whatever reason?
     
  4. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    994
    Well, as you can see, user_name is -4 in your debug window. And -4 happens to be the value of noone.. Hopefully you can correlate this with your code.
     
  5. Zain birdie

    Zain birdie Guest

    how do I create a new post ???
     
  6. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    994
    Click forum topic that is relevant, then click "Post New Thread" in top right corner.
     
  7. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    If you are on a mobile device you must turn it sideways to landscape view to see the post new topic link

    Oops sorry that scenerio is used to view the search the forum option
     
  8. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    I agree with @chamaeleon ,
    You definatly shouldnt be changing variables in the draw event that aren't directly nessesary for drawing, if you continue to do this it will come back to haunt you.
    And it looks to me like the problem is occuring when you set tt to keyboard_string, you should use
    Code:
    tt = string(keyboard_string);
    instead of just
    Code:
    tt = keyboard_string;
     
  9. Zain birdie

    Zain birdie Guest

     
  10. XirmiX

    XirmiX Member

    Joined:
    Jul 18, 2016
    Posts:
    365
    Okay, fair enough. If this was web programming, it would be like CSS doing javascript's work. But the thing is, the code has both draw elements and basic mechanical elements... so, this is how I changed it around. Now code is as follows (the script still has all the same code):

    Create event
    Code:
    self.selected = false;
    self.max_char = 30;
    self.char_written = 0;
    txt = "";
    tt = "";
    
    draw_txt = false;
    draw_tt = false;
    
    enter_string = 0;
    
    show_debug_message("txt: " + txt);
    show_debug_message("tt: " + tt);
    
    leftX = x - (sprite_width/2);
    topY = y - (sprite_width/2);
    rightX = x + (sprite_width/2);
    bottomY = y + (sprite_height/2);
    
    Step event
    Code:
    ///Checking instance id for sending text where needed
    {
    if self.selected == true
    {
        self.tt = keyboard_string;//set keyboard string to a temp var
        //make sure it doesnt go over the desired length
        if (string_length(self.tt) > 30)
        {
            //if it does go over we set it back to the correct length
            keyboard_string = string_copy(self.tt, 1, 30);
            self.txt = tt;
        }
        //these are just to update text variable (this is the variable to hold the key string value)
        var update_keys = keyboard_check_pressed(vk_backspace) || keyboard_check_pressed(vk_enter);
        if (update_keys)
        {
            self.txt = self.tt;
        }
        self.txt = self.tt;
        draw_tt = true;//draw the text
    }
    else
    {
        draw_txt = true;//this is the text when not selected
    }
    if keyboard_check(vk_enter)
    {
        switch(self.enter_string)
        {
            case 1: //username register
                show_debug_message("user_name txt: " + self.txt);
                scr_register_handling(self.txt);
            break;
            case 2: //password register
                show_debug_message("pass_word txt: " + self.txt);
                scr_register_handling(noone, self.txt);
            break;
            case 3: //password confirmation
            show_debug_message("pass_word_confirm txt: " + self.txt);
                scr_register_handling(noone, noone, self.txt);
            break;
            case 4: //username login
                scr_login_handling(self.txt);
                obj_dataholder.logged_username = self.txt;
            break;
            case 5: //password login
                scr_login_handling(noone, self.txt);
            break;
        }
    }
    }
    
    Draw event
    Code:
    draw_self();
    draw_set_colour(c_lime);
    //draw_text(x-56, y, txt);
    
    if draw_tt == true
    {
        draw_text(x-56, y, self.tt);//draw the text
    }
    if draw_txt == true
    {
        draw_text(x-56, y, self.txt);//this is the text when not selected
    }
    
    Yet still, it gives the same error:
    upload_2017-7-29_11-25-49.png
    What could be going on? I mean, yes, in the step event, I have things set too "noone" in places, but that's because I don't want anything to be sent as those arguments. I'm guessing that's the problem! How can I make a line of code such as scr_register_handling(noone, noone, self.txt); not send anything to the script as the first two arguments, so that it can keep the first two arguments from the previous instances that sent it information (because you have 3 instances of the same object sending different pieces of information to the script, depending on what a variable for that instance is declared to)?
     
  11. XirmiX

    XirmiX Member

    Joined:
    Jul 18, 2016
    Posts:
    365
    Or alternatively, I changed code to make it so that the first two instances (username textbox and password textbox) create global variables that are defined as their text and then have the third instance (password confirm) take those and send it all to the script. I even commented out the cases 4 and 5:

    Code:
    if self.selected == true
    {
        self.tt = keyboard_string;//set keyboard string to a temp var
        //make sure it doesnt go over the desired length
        if (string_length(self.tt) > 30)
        {
            //if it does go over we set it back to the correct length
            keyboard_string = string_copy(self.tt, 1, 30);
            self.txt = tt;
        }
        //these are just to update text variable (this is the variable to hold the key string value)
        var update_keys = keyboard_check_pressed(vk_backspace) || keyboard_check_pressed(vk_enter);
        if (update_keys)
        {
            self.txt = self.tt;
        }
        self.txt = self.tt;
        draw_tt = true;//draw the text
    }
    else
    {
        draw_txt = true;//this is the text when not selected
    }
    if keyboard_check(vk_enter)
    {
        switch(self.enter_string)
        {
            case 1: //username register
                show_debug_message("user_name txt: " + self.txt);
                global.user_box_id = self.txt;
                //scr_register_handling(self.txt);
            break;
            case 2: //password register
                show_debug_message("pass_word txt: " + self.txt);
                global.pass_box_id = self.txt;
                //scr_register_handling(noone, self.txt);
            break;
            case 3: //password confirmation
            show_debug_message("pass_word_confirm txt: " + self.txt);
                scr_register_handling(global.user_box_id, global.pass_box_id, self.txt);
            break;
            /*
            case 4: //username login
                scr_login_handling(self.txt);
                obj_dataholder.logged_username = self.txt;
            break;
            case 5: //password login
                scr_login_handling(noone, self.txt);
            break;*/
        }
    }
    
    However, even then the error still occurs. Help! I've ran out of ideas on how to fix this :(
     
  12. sp202

    sp202 Member

    Joined:
    Sep 26, 2016
    Posts:
    967
    You're still using the self prefix for every instance variable? I thought I explained to you that it does nothing and you're wasting time typing 5 extra characters each time.
     
  13. XirmiX

    XirmiX Member

    Joined:
    Jul 18, 2016
    Posts:
    365
    I know, I know, but I just want to be safe, and it works as a reminder of what the code is for, and it's for each instance separately and not all instances.

    Regardless, it isn't creating my problem. What IS making the error occur, I have no idea, and that's why I'm asking here.
     
  14. sp202

    sp202 Member

    Joined:
    Sep 26, 2016
    Posts:
    967
    You don't understand how variables are scoped and that's a big issue. Self is doing absolutely nothing, variables are instance scoped by default meaning they refer to the variables within the instance and not to all instances of an object as you seem to believe.

    Can you please repost the code without the comments and the selfs.
     
  15. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    Ahh wait, I see you are trying to set the keyboard_string built in variable, I'm not sure you can set that, it only gets changed by keyboard input as far as I know but I could be wrong, I'll test it when I get to my computer
     
  16. TimothyAllen

    TimothyAllen Member

    Joined:
    Aug 7, 2016
    Posts:
    429
    You are making the error lol. You keep passing noone as arguments into your script... noone is nothing more than a GM constant that holds the value -4.... which IS NOT A STRING. Stop passing noone as an argument that your script expects to be a string.
     
    Wraithious likes this.
  17. sp202

    sp202 Member

    Joined:
    Sep 26, 2016
    Posts:
    967
    Wraithious likes this.
  18. XirmiX

    XirmiX Member

    Joined:
    Jul 18, 2016
    Posts:
    365
    Well, the error seems to say the script is expecting a string, though yes, I have not set a code for that. How does this matter though? Script should just take what it's fed, and if I send a string, it better be saving a string... that was snarky, but is that not how this is supposed to work? Anyway I removed all of the "self." (21 total), since you're so triggered by them, still no change in execution though:

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

    global variable <unknown built-in variable>(-1610512735, -2147483648) not set before reading it.
    at gml_Object_obj_textbox_StepNormalEvent_1 (line 47) - scr_register_handling(global.user_box_id, global.pass_box_id, txt);
    ############################################################################################

    Create event code
    Code:
    selected = false;
    max_char = 30;
    char_written = 0;
    txt = "";
    tt = "";
    
    draw_txt = false;
    draw_tt = false;
    
    enter_string = 0;
    
    show_debug_message("txt: " + txt);
    show_debug_message("tt: " + tt);
    
    leftX = x - (sprite_width/2);
    topY = y - (sprite_width/2);
    rightX = x + (sprite_width/2);
    bottomY = y + (sprite_height/2);
    
    Step event code
    Code:
    if selected == true
    {
        tt = keyboard_string;//set keyboard string to a temp var
        //make sure it doesnt go over the desired length
        if (string_length(tt) > 30)
        {
            //if it does go over we set it back to the correct length
            keyboard_string = string_copy(self.tt, 1, 30);
            txt = tt;
        }
        //these are just to update text variable (this is the variable to hold the key string value)
        var update_keys = keyboard_check_pressed(vk_backspace) || keyboard_check_pressed(vk_enter);
        if (update_keys)
        {
            txt = tt;
        }
        txt = tt;
        draw_tt = true;//draw the text
    }
    else
    {
        draw_txt = true;//this is the text when not selected
    }
    
    if keyboard_check(vk_enter)
    {
        switch(self.enter_string)
        {
            case 1: //username register
                show_debug_message("user_name txt: " + txt);
                global.user_box_id = txt;
                //scr_register_handling(self.txt);
            break;
            case 2: //password register
                show_debug_message("pass_word txt: " + txt);
                global.pass_box_id = txt;
                //scr_register_handling(noone, self.txt);
            break;
            case 3: //password confirmation
                show_debug_message("pass_word_confirm txt: " + txt);
                scr_register_handling(global.user_box_id, global.pass_box_id, txt);
            break;
            /*
            case 4: //username login
                scr_login_handling(self.txt);
                obj_dataholder.logged_username = self.txt;
            break;
            case 5: //password login
                scr_login_handling(noone, self.txt);
            break;*/
        }
    }
    
    Draw event code
    Code:
    draw_self();
    draw_set_colour(c_lime);
    //draw_text(x-56, y, txt);
    
    if draw_tt == true
    {
        draw_text(x-56, y, tt);//draw the text
    }
    if draw_txt == true
    {
        draw_text(x-56, y, txt);//this is the text when not selected
    }
    
    Script code
    Code:
    //Sets the three registration values as arguments
    {
    user_name = argument[0];
    pass_word = argument[1];
    pass_word_confirm = argument[2];
    
    show_debug_message("user_name: " + user_name);
    show_debug_message("pass_word: " + pass_word);
    show_debug_message("pass_word_confirm: " + pass_word_confirm);
    
    if (user_name == "")
    {
        scr_message_display("Please enter a username")
    }
    else if file_exists(user_name)
    {
        scr_message_display("Username has already been taken by someone using your machine");
      
        /*
        with instance_number(obj_textbox)
        {
            sprite_index = ;
        }*/
    }
    else
    {
        if (pass_word != pass_word_confirm)
        {
            scr_message_display("Confirmation password does not match the password you entered")
        }
        else
        {
            //irrelevant code
        }
    }
    }
    

    Second time now someone's not caught up with things... Read my previous post, or just look above, I guess. There's no more "noone" and the error is still occurring.
     
  19. TimothyAllen

    TimothyAllen Member

    Joined:
    Aug 7, 2016
    Posts:
    429
    eh... I still see a noone.

    EDIT: Oh I see it is commented out.
    EDIT2: So when and where do you initialize global.user_box_id and global.pass_box_id. It seems the new error is just saying one of those variables does not exist yet.
     
    Last edited: Jul 29, 2017
  20. sp202

    sp202 Member

    Joined:
    Sep 26, 2016
    Posts:
    967
    The script takes the arguments it's given, correct, but you're the one treating that argument like a string by using it in file_exists. The real problem is that you're not sending a string, you're sending an id which is a real value.

    You removed the selfs for my sake? Because I'm "triggered by them" (which is quite an immature thing to say)? If you'd like to spend time typing out the selfs because you like the way they look, be my guest.
     
  21. trolog

    trolog Member

    Joined:
    Dec 26, 2016
    Posts:
    8
    Are you defining global.user_box_id and global.pass_box_id BEFORE they are used?

    EDIT: You aren't defining the variables before passing them in as arguments
     
    XirmiX likes this.
  22. chamaeleon

    chamaeleon Member

    Joined:
    Jun 21, 2016
    Posts:
    994
    You can't state "the error is still occurring" when it is not the same error. You should say "a different error is occurring". In other words, previously you needed to find out that noone (a number) was being added to a string, something gms does not allow. Now you need to figure out why a global variable is not set.
     
    XirmiX likes this.
  23. trolog

    trolog Member

    Joined:
    Dec 26, 2016
    Posts:
    8
    Teh global variables are not set in CASE 3


    case 3: //password confirmation
    show_debug_message("pass_word_confirm txt: " + txt);
    scr_register_handling(global.user_box_id, global.pass_box_id, txt);
    break;

    It's possible to hit this code without setting the global.user_box_id and global.pass_box_id

    Hope this is clear?
     
    XirmiX likes this.
  24. XirmiX

    XirmiX Member

    Joined:
    Jul 18, 2016
    Posts:
    365
    @trolog and @chamaeleon (would be useful if you put up profile pictures, as sometimes it's hard to differentiate whether someone was the same user or not) the global variables were executed at the same time as the script arguments were sent. I never thought this could even be a thing that could occur, but now thinking about it, it does make sense, so I just needed to put the code in an alarm and set the alarm to 1 (frame).
     
  25. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    In your script, you define some variables according to 3 arguments, but in your step event (I know you now have the lines commented out to not call the script yet, BUT when you do) you're not passing all 3 arguments every time the script can be called, that will result in a crash too, the script will expect 3 arguments every time it is called no matter what. but to see what's going on with the debug message crashing change:
    Code:
            case 1: //username register
                show_debug_message("user_name txt: " + txt);
                //scr_register_handling(txt);
            break;
            case 2: //password register
                show_debug_message("pass_word txt: " + txt);
                //scr_register_handling(noone, txt);
            break;
            case 3: //password confirmation
            show_debug_message("pass_word_confirm txt: " + txt);
                //scr_register_handling(noone, noone, txt);
            break;
    to:
    Code:
    case 1: //username register
                show_debug_message("user_name txt: " + string(txt));
                //scr_register_handling(txt,"","");              //MUST SEND all 3 arguments, can't use noone
            break;
            case 2: //password register
                show_debug_message("pass_word txt: "+ string(txt));
                //scr_register_handling("", txt,"");             //MUST SEND all 3 arguments, can't use noone
            break;
            case 3: //password confirmation
            show_debug_message("pass_word_confirm txt: "+ string(txt));
                //scr_register_handling("", "", txt);             //THIS one was correct, you sent all three arguments, but you still can't use noone
            break;
    
    //Same deal when you go to uncomment cases 4 and 5
    and see what you get in your debug message and debugger output.

    Also just wondering, did you define the variables user_name, pass_word and pass_word_confirm in the create event of your object that calls the script?
     
    Last edited: Jul 29, 2017
  26. XirmiX

    XirmiX Member

    Joined:
    Jul 18, 2016
    Posts:
    365
    @Wraithious those variables are arguments in the script, they are declared in the script. I have it all fixed now; what happens now is that the first two textbox instances declare their text as global variables. Then, for the thirs textbox, it will now call an alarm 1 frame later, so that the first two textboxes can declare those variables. After that, the alarm for that textbox will take those global variables that the previous two text boxes declared, as well as the third textbox's string and send it all to the script at once. Currently I'm getting an error, but it's due to an unrelated reason to this. This has been fixed, as far as I can tell.
     
  27. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    Ok but still in your step event code you aren't passing all the arguments all the time, if you pass 1 argument to the script then later pass 2 or 3 your script will crash, I'm just saying you have to pass all the arguments every time weather the script uses them or not.
     
  28. XirmiX

    XirmiX Member

    Joined:
    Jul 18, 2016
    Posts:
    365
    Okay, I got it, it IS passing all of the arguments at the same time now, otherwise it wouldn't work for me right now. Now that I have this working, I can finally put my focus on two different things, one being text displays (just messages, for indication) and getting a second player connected to the server, which, and I checked, should run fine, but crashes the server upon a second player joining... anyway, thanks for all your support everyone!
     
    Wraithious likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice