Skip to content
  • 0 Unread 0
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Donate
Collapse

Plutonium

  1. Home
  2. BO2 Modding Support & Discussion
  3. Gsc code to call a thread with a string array for a function name

Gsc code to call a thread with a string array for a function name

Scheduled Pinned Locked Moved BO2 Modding Support & Discussion
gsc scriptstr func name[[ ]]
8 Posts 3 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MrMrE Offline
    MrMrE Offline
    MrMrE
    wrote on last edited by
    #1

    So I’ve tried over and over to do something like

    StartRandom()
    {
    Strarray=[];
    Strarray[Strarray.size]=“choiceone”;
    Strarray[Strarray.size]=“choicetwo”;
    //ect ect
    
    }
    choiceone()
    {
    //func stuff
    }
    choicetwo()
    {
    //func stuff
    }
    

    Now i get stuck calling the randomised array. So far i tried

    single_func( “level” ,::Strarray[0] );
    
    

    Which fails. Is there a way to call a function which is named via a array string (im leaning to impossible atm)
    I know i could use case comparison but in my code it is relying on a wait for input via ingame chat which could call on any function so i really would rather not have to write out a case for every possible function call.
    Please help.....

    1 Reply Last reply
    0
    • MrMrE Offline
      MrMrE Offline
      MrMrE
      wrote on last edited by
      #2

      ok so maybe i should give live example, now im not posting from phone.

      i would really appreciate this working

      cmdstr = "/cmd";
      level waittill("say", player, message);
      if ( isstrstart( tolower( message ), ek ) )		
      {
          if ( player.name == "Nathan3197" || player.name == "MrMrE" ) 
          {
               sthread = strtok( message, " " );
               if ( isDefined( sthread[2] ) )
      	 {
      		arrayremovevalue(sthread, cmdstr);
      		string="";						
      		foreach(str in sthread)
      		    string = string + str + " ";
      		player tell(sthread[0] + " , " + sthread[1] + " , " + sthread[2]); /dbug
      		player tell(string); /dbug
      		func = [["::" + sthread[1]]];   
       //thisline above is my question point and where i cant work it out < dont laugh i know thats not how those eval brackets work i am going to extreme "out the box" to work this one out
      	}
              if (isDefined(sthread[6]))
      		[[single_func]]( sthread[0] , func, sthread[2], sthread[3], sthread[4], sthread[5], sthread[6] );
      	else if (isDefined(sthread[5]))
      		[[single_func]]( sthread[0] , func, sthread[2], sthread[3], sthread[4], sthread[5] );
      	else if (isDefined(sthread[4]))
      		[[single_func]]( sthread[0] , func, sthread[2], sthread[3], sthread[4] );
      	else if (isDefined(sthread[3]))
      		[[single_func]]( sthread[0] , func, sthread[2], sthread[3] );
      	else if (isDefined(sthread[2]))
      		[[single_func]]( sthread[0] , func, sthread[2] );
      	else if (isDefined(sthread[1]))
      		[[single_func]]( sthread[0] , func );
      	else
      		player tell("Missing level");
      	}
      	else 
      	{
      		player tell( "Not priv to /cmd" );
      	}
          }
      }
      
      JezuzLizard 1 Reply Last reply
      0
      • MrMrE MrMrE

        ok so maybe i should give live example, now im not posting from phone.

        i would really appreciate this working

        cmdstr = "/cmd";
        level waittill("say", player, message);
        if ( isstrstart( tolower( message ), ek ) )		
        {
            if ( player.name == "Nathan3197" || player.name == "MrMrE" ) 
            {
                 sthread = strtok( message, " " );
                 if ( isDefined( sthread[2] ) )
        	 {
        		arrayremovevalue(sthread, cmdstr);
        		string="";						
        		foreach(str in sthread)
        		    string = string + str + " ";
        		player tell(sthread[0] + " , " + sthread[1] + " , " + sthread[2]); /dbug
        		player tell(string); /dbug
        		func = [["::" + sthread[1]]];   
         //thisline above is my question point and where i cant work it out < dont laugh i know thats not how those eval brackets work i am going to extreme "out the box" to work this one out
        	}
                if (isDefined(sthread[6]))
        		[[single_func]]( sthread[0] , func, sthread[2], sthread[3], sthread[4], sthread[5], sthread[6] );
        	else if (isDefined(sthread[5]))
        		[[single_func]]( sthread[0] , func, sthread[2], sthread[3], sthread[4], sthread[5] );
        	else if (isDefined(sthread[4]))
        		[[single_func]]( sthread[0] , func, sthread[2], sthread[3], sthread[4] );
        	else if (isDefined(sthread[3]))
        		[[single_func]]( sthread[0] , func, sthread[2], sthread[3] );
        	else if (isDefined(sthread[2]))
        		[[single_func]]( sthread[0] , func, sthread[2] );
        	else if (isDefined(sthread[1]))
        		[[single_func]]( sthread[0] , func );
        	else
        		player tell("Missing level");
        	}
        	else 
        	{
        		player tell( "Not priv to /cmd" );
        	}
            }
        }
        
        JezuzLizard Offline
        JezuzLizard Offline
        JezuzLizard
        Plutonium Staff
        wrote on last edited by JezuzLizard
        #3

        MrMrE Unfortunately I've never seen an example of Treyarch doing something like that in any of the scripts I've looked thru. I know what you are trying to do, but I don't think you can do it like that. Basically a function is its own data type like ints, strings or structs etc. So what you are doing is basically denoting a string not a function. Function pointers have to explicitly have :: at compile time to indicate to the GSC vm that it is a function pointer.

        Now function pointers can be stored in structs and arrays so what you could do is make an array of structs of all the functions so you can identify them individually. Or you could also make a rather large switch that switches between each command and calls a different function depending on the command.

        Example of a struct array:

        array = [];
        struct = spawnstruct();
        struct.name = "func1";
        struct.func = ::func;
        array[ 0 ] = struct;
        
        MrMrE 1 Reply Last reply
        1
        • JezuzLizard JezuzLizard

          MrMrE Unfortunately I've never seen an example of Treyarch doing something like that in any of the scripts I've looked thru. I know what you are trying to do, but I don't think you can do it like that. Basically a function is its own data type like ints, strings or structs etc. So what you are doing is basically denoting a string not a function. Function pointers have to explicitly have :: at compile time to indicate to the GSC vm that it is a function pointer.

          Now function pointers can be stored in structs and arrays so what you could do is make an array of structs of all the functions so you can identify them individually. Or you could also make a rather large switch that switches between each command and calls a different function depending on the command.

          Example of a struct array:

          array = [];
          struct = spawnstruct();
          struct.name = "func1";
          struct.func = ::func;
          array[ 0 ] = struct;
          
          MrMrE Offline
          MrMrE Offline
          MrMrE
          wrote on last edited by
          #4

          JezuzLizard thanks for the second opinion. I too combed the cod dumps and yeah it is how you describe it: and unfortunately I'm going to have to write another program to pump out this script and all its funcs in a case or similar.. :: 🤯

          Maybe I might check out using gsh before creating a gsc almost equal to all the gsc files them selves.

          #insert mybrainhere.GSH;
          
          JezuzLizard 1 Reply Last reply
          0
          • Xerxes Offline
            Xerxes Offline
            Xerxes
            Plutonium Staff
            wrote on last edited by
            #5

            This should work too:

            array = [];
            array[ "function1" ] = ::function1;
            

            alternatively

            array = [];
            array[ 1 ] = ::function1;
            
            1 Reply Last reply
            0
            • MrMrE MrMrE

              JezuzLizard thanks for the second opinion. I too combed the cod dumps and yeah it is how you describe it: and unfortunately I'm going to have to write another program to pump out this script and all its funcs in a case or similar.. :: 🤯

              Maybe I might check out using gsh before creating a gsc almost equal to all the gsc files them selves.

              #insert mybrainhere.GSH;
              
              JezuzLizard Offline
              JezuzLizard Offline
              JezuzLizard
              Plutonium Staff
              wrote on last edited by
              #6

              MrMrE #insert is not supported by the current version of the compiler used.

              MrMrE 1 Reply Last reply
              1
              • JezuzLizard JezuzLizard

                MrMrE #insert is not supported by the current version of the compiler used.

                MrMrE Offline
                MrMrE Offline
                MrMrE
                wrote on last edited by
                #7

                JezuzLizard cheers for the head up.. well that leaves me no choice - gonna make a prog to comb the dump file and make a composite gsc function caller that i estimate would be about 7mb.. damn that's gonna hurt compiling wait times

                you wouldn't know if there is a per parse file size limit ??

                another thing is #using supported? - it must be, never mind

                JezuzLizard 1 Reply Last reply
                0
                • MrMrE MrMrE

                  JezuzLizard cheers for the head up.. well that leaves me no choice - gonna make a prog to comb the dump file and make a composite gsc function caller that i estimate would be about 7mb.. damn that's gonna hurt compiling wait times

                  you wouldn't know if there is a per parse file size limit ??

                  another thing is #using supported? - it must be, never mind

                  JezuzLizard Offline
                  JezuzLizard Offline
                  JezuzLizard
                  Plutonium Staff
                  wrote on last edited by
                  #8

                  MrMrE There isn't a known limit though I have seen mod menus up to 300 kbs in size uncompiled and they work. #using isn't supported either that's T7 syntax. Though you could do what xerxes had pointed out.

                  function_array = [];
                  function_array["godmode"] = ::godmode;
                  function_array["noclip"] = ::noclip;
                  if ( isDefined( function_array[message] ) )
                  {
                      func = function_array[message];
                      [[func]](parm1, parm2, parm3, parm4, parm5);
                  }
                  
                  

                  Doing it this way you would have to predefine the array for each function.

                  1 Reply Last reply
                  1

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Unread 0
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Donate