Pages: [1]
  Print  
Author Topic: Unknown function or script `string_copy'?  (Read 483 times)
Offline (Unknown gender) TacoBot
Posted on: July 12, 2016, 09:50:14 PM
Member
Joined: Feb 2015
Posts: 15

View Profile
So when I try to compile my lil game, which makes use of the "string_copy" function, it tells me " Unknown function or script `string_copy' "

Is this function not implemented in ENIGMA, and if not, is there any alternative I could use to trim strings?
Logged
Offline (Unknown gender) TacoBot
Reply #1 Posted on: July 12, 2016, 10:09:48 PM
Member
Joined: Feb 2015
Posts: 15

View Profile
I have a sneaking suspicion that this is happening because I'm using it in a switch case...

Here's the code in question:

Code: [Select]
//gj_checkstatus()
//Returns: true if the function is completed, false if there is an GameJolt error, <0 if there is a GameMaker error (for example, if GM couldn't find the site).
//If returns 0, more info will be available when you call gj_error()
//Returns the status and makes the info available, so ALWAYS call this before you request any info.
var httpstatus=ds_map_find_value(async_load,"status");
if(httpstatus<0)
{
    return httpstatus;
}
else
{
    var datatype=ds_map_find_value(gj_handletypemap,ds_map_find_value(async_load,"id"));
    if(datatype==4) //dump format
    {
        var gj_returnstring=ds_map_find_value(async_load,"result");
        ds_map_delete(gj_handletypemap,ds_map_find_value(async_load,"id"))
        switch(string_copy(gj_returnstring,1,7))
        {
            case "SUCCESS":
                gj_returnstring=string_delete(gj_returnstring,1,9)
                ds_map_clear(gj_infomap)
                ds_map_add(gj_infomap,"0data",gj_returnstring)
                return true;
            break;
            case "FAILURE":
                gj_returnstring=string_delete(gj_returnstring,1,9)
                ds_map_clear(gj_infomap)
                ds_map_add(gj_infomap,"error",gj_returnstring)
                return false;
            break;
        }
    }
    else
    {
        //Make a ds_map with the information
        //First clear our info map
        ds_map_clear(gj_infomap)
        var gj_key="",gj_value="",gj_returnstring=ds_map_find_value(async_load,"result");
        //Now removed because of HTML5
        //gj_returnstring=string_replace_all(gj_returnstring,"","") //make it easier to read the map by removing all newlines.
        //show_message(gj_returnstring) //Debugging
        gj_returnstring=string_replace_all(gj_returnstring,'\"',"''") //Sorry, couldn't find a better way to do this.
        //First always check the first line, as this always contains the status
        gj_key=string_copy(gj_returnstring,1,string_pos(':"',gj_returnstring)-1)
        gj_returnstring=string_delete(gj_returnstring,1,string_pos(':"',gj_returnstring)+1)
        gj_value=string_copy(gj_returnstring,1,string_pos('"',gj_returnstring)-1)
        gj_returnstring=string_delete(gj_returnstring,1,string_pos('"',gj_returnstring)+2)
        if(gj_value="true")
        {
            //Succes! Now we can read the rest of the map, if the call needs it, else just return true.
            switch(datatype)
            {
                case 0:
                    gj_user=gj_tempuser
                    gj_token=gj_temptoken
                    gj_tempuser=""
                    gj_temptoken=""
                break;
                case 1:
                    var gj_currnum=0;
                    while(gj_returnstring!="")
                    {
                            gj_key=string_copy(gj_returnstring,1,string_pos(':"',gj_returnstring)-1)
                            gj_returnstring=string_delete(gj_returnstring,1,string_pos(':"',gj_returnstring)+1)
                            gj_value=string_copy(gj_returnstring,1,string_pos('"',gj_returnstring)-1)
                            gj_returnstring=string_delete(gj_returnstring,1,string_pos('"',gj_returnstring)+2)
                            if(ds_map_exists(gj_infomap,string(gj_currnum)+gj_key))
                            {
                                gj_currnum+=1
                            }
                            ds_map_add(gj_infomap,string(gj_currnum)+gj_key,gj_value)
                    }
                    ds_map_add(gj_infomap,"fieldnum",gj_currnum)
                break;
                //Case 3 is the same as 1, but then for highscores with guests. We add the is_guest var here.
                case 3:
                    var gj_currnum=0;
                    while(gj_returnstring!="")
                    {
                            gj_key=string_copy(gj_returnstring,1,string_pos(':"',gj_returnstring)-1)
                            gj_returnstring=string_delete(gj_returnstring,1,string_pos(':"',gj_returnstring)+1)
                            gj_value=string_copy(gj_returnstring,1,string_pos('"',gj_returnstring)-1)
                            gj_returnstring=string_delete(gj_returnstring,1,string_pos('"',gj_returnstring)+2)
                            //show_message(gj_returnstring) //Debugging
                            if(ds_map_exists(gj_infomap,string(gj_currnum)+gj_key))
                            {
                                gj_currnum+=1
                            }
                            if(gj_key=="user")
                            {
                                if(gj_value=="")
                                ds_map_add(gj_infomap,string(gj_currnum)+"is_guest",1)
                                else
                                {
                                    ds_map_add(gj_infomap,string(gj_currnum)+"is_guest",0)
                                    ds_map_add(gj_infomap,string(gj_currnum)+"display_name",gj_value)
                                }
                            }
                            if(gj_key="guest")and(gj_value!="")
                            {
                                ds_map_add(gj_infomap,string(gj_currnum)+"display_name",gj_value)
                            }
                            ds_map_add(gj_infomap,string(gj_currnum)+gj_key,gj_value)
                    }
                    ds_map_add(gj_infomap,"fieldnum",gj_currnum)
                break;
            }
            //Then remove the handle id from the map, as it is no longer needed.
            ds_map_delete(gj_handletypemap,ds_map_find_value(async_load,"id"))
            return true;
        }
        else
        {
            //The error is on the next line now
            gj_key=string_copy(gj_returnstring,1,string_pos(':"',gj_returnstring)-1)
            gj_returnstring=string_delete(gj_returnstring,1,string_pos(':"',gj_returnstring)+1)
            gj_value=string_copy(gj_returnstring,1,string_pos('"',gj_returnstring)-1)
            gj_returnstring=string_delete(gj_returnstring,1,string_pos('"',gj_returnstring)+2)
            //Add it to our ds_map so we can find it later if gj_error is called
            ds_map_add(gj_infomap,"error",gj_value)
            return false;
        }
    }
}
« Last Edit: July 12, 2016, 10:12:45 PM by TacoBot » Logged
Offline (Male) faissaloo
Reply #2 Posted on: July 13, 2016, 05:28:05 AM

Member
Location: Britbongistan
Joined: Jan 2013
Posts: 70

View Profile WWW Email
Copy and paste this into line 22 of ./enigma-dev/ENIGMAsystem/SHELL/SHELLmain.cpp
It's a weird issue with newer versions of GCC.
Code: [Select]
#ifndef JUST_DEFINE_IT_RUN
  #include <string>
#else
  #define _GLIBCXX_STRING 1
  template<typename T, typename traits = int> class basic_string {};
  typedef basic_string<char> string;
#endif
Logged
Offline (Unknown gender) TacoBot
Reply #3 Posted on: July 13, 2016, 06:16:56 PM
Member
Joined: Feb 2015
Posts: 15

View Profile
Works like a charm! Thank you very much.
Logged
Offline (Male) faissaloo
Reply #4 Posted on: July 14, 2016, 05:16:11 AM

Member
Location: Britbongistan
Joined: Jan 2013
Posts: 70

View Profile WWW Email
No problem, but Josh is the one you should really thank, he's the one that figured it out.
Logged
Pages: [1]
  Print