Results 1 to 4 of 4
  1. #1
    master131's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    8,827
    Reputation
    3310
    Thanks
    74,539
    My Mood
    Breezy

    Using variables as functions.

    Well have you ever seen code like this and thought wtf?
    Code:
    [[level.callbackStartGameType]]();
    That is was I call a variable function. It runs a function that is assigned to a variable. If you search through the game's files you will find this:
    Code:
    level.callbackStartGameType = maps\mp\gametypes\_globallogic::Callback_StartGameType;
    What that means is the code in the first box runs the function that is assigned in the second box. Now that we have found out this. We can use variables as functions.

    Say, inside my _rank.gsc file I had these two sub-procedures (, VB):
    Code:
    onPlayerSpawned()
    {
        self endon("disconnect");
        for(;;)
        {
            self waittill("spawned_player");
        }
    }
    
    doSuicide()
    {
        self suicide();
    }
    How do I run doSuicide() as a function?
    Well first you need to declare your function. Lets name it byeCruelWorld. To link it to a function that's in the same file and then run it, you do this:
    Code:
    byeCruelWorld = ::doSuicide;
    self [[byeCruelWorld]]();
    Now my onPlayerSpawned looks like this:
    Code:
    onPlayerSpawned()
    {
        self endon("disconnect");
        for(;;)
        {
            self waittill("spawned_player");
            byeCruelWorld = ::doSuicide;
            self [[byeCruelWorld]]();
        }
    }
    So now when I spawn, it runs the function that is assigned to 'byeCruelWorld' which causes me to commit suicide. However there is a downside since I can only use 'byeCruelWorld' in the same function for obvious reasons.

    What if I want to use this function in anywhere BUT the function is in the same file I'm delcaring it in?
    You would do this and delcare it as a global variable.
    Code:
    self.byeCruelWorld = ::doSuicide;
    // In any file:
    self [[self.byeCruelWorld]]();
    What if I want to use this function in anywhere AND the function is in another file?
    You would link it in a simillar manner of running a function or thread from another file.
    Code:
    self.byeCruelWorld = maps\mp\gametypes\_rank::doSuicide;
    // In any file:
    self [[self.byeCruelWorld]]();
    What if I want to pass arguments through?
    You pass your arguments through the pair of brackets before the semi-colon.
    Code:
    level.endGameNow = maps\mp\gametypes\_globallogic::endGame;
    level [[level.endGameNow]]("allies", "Allies rule!");
    What if I want to thread the variable function?
    Simple, just add 'thread' before the variable.
    Code:
    self thread [[self.byeCruelWorld]]();
    Last edited by master131; 01-08-2011 at 08:23 PM.
    Donate:
    BTC: 1GEny3y5tsYfw8E8A45upK6PKVAEcUDNv9


    Handy Tools/Hacks:
    Extreme Injector v3.7 *NEW* 2017 Update!
    A powerful and advanced injector in a simple GUI.
    Can scramble DLLs on injection making them harder to detect and even make detected hacks work again!

    Minion Since: 13th January 2011
    Moderator Since: 6th May 2011
    Global Moderator Since: 29th April 2012
    Super User/Unknown Since: 23rd July 2013
    'Game Hacking' Team Since: 30th July 2013

    --My Art--
    [Roxas - Pixel Art, WIP]
    [Natsu - Drawn]
    [Natsu - Coloured]


    All drawings are coloured using Photoshop.

    --Gifts--
    [Kyle]

  2. The Following 3 Users Say Thank You to master131 For This Useful Post:

    ♪~ ᕕ(ᐛ)ᕗ (01-15-2011),[MPGH]Insane (01-15-2011),sammysfat (01-15-2011)

  3. #2
    Insane's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Posts
    9,055
    Reputation
    1007
    Thanks
    2,001
    Very useful. Gj Master

  4. #3
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    8,820
    Reputation
    781
    Thanks
    1,857
    My Mood
    Doh
    useful and sexy =P Gewd job dude!
    /Thanked

  5. #4
    sammysfat's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Posts
    89
    Reputation
    10
    Thanks
    9
    My Mood
    Breezy
    that is cool ur teaching me alot