Skip to content
  • 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 613 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MrMrEundefined Offline
    MrMrEundefined 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
    • MrMrEundefined Offline
      MrMrEundefined 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" );
      	}
          }
      }
      
      JezuzLizardundefined 1 Reply Last reply
      0
      • JezuzLizardundefined Offline
        JezuzLizardundefined Offline
        JezuzLizard Plutonium Staff
        replied to MrMrE 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;
        
        MrMrEundefined 1 Reply Last reply
        1
        • MrMrEundefined Offline
          MrMrEundefined Offline
          MrMrE
          replied to JezuzLizard 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;
          
          JezuzLizardundefined 1 Reply Last reply
          0
          • Xerxesundefined Offline
            Xerxesundefined 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
            • JezuzLizardundefined Offline
              JezuzLizardundefined Offline
              JezuzLizard Plutonium Staff
              replied to MrMrE on last edited by
              #6

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

              MrMrEundefined 1 Reply Last reply
              1
              • MrMrEundefined Offline
                MrMrEundefined Offline
                MrMrE
                replied to JezuzLizard 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

                JezuzLizardundefined 1 Reply Last reply
                0
                • JezuzLizardundefined Offline
                  JezuzLizardundefined Offline
                  JezuzLizard Plutonium Staff
                  replied to MrMrE 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

                  • Login

                  • Don't have an account? Register

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