Results 1 to 4 of 4
  1. #1
    master131's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    8,802
    Reputation
    3165
    Thanks
    73,324
    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 09:23 PM.
    Donate:
    BTC: 1GEny3y5tsYfw8E8A45upK6PKVAEcUDNv9


    Handy Tools/Hacks:
    Extreme Injector v3.6.1 *NEW* Windows 10 compatible!
    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
    1,997
    Very useful. Gj Master
    Insane
    Ex Middleman
    [
    PM|VM]
    |x|x|x|x|x|x|x|



    Quote Originally Posted by Boombox View Post
    Shut the fuck up insane you pussy bitch.
    Quote Originally Posted by arunforce View Post
    Shut the fuck up kid, everything that comes out of your mouth sounds retarded as fuck.

  4. #3
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    8,643
    Reputation
    748
    Thanks
    1,818
    My Mood
    Doh
    useful and sexy =P Gewd job dude!
    /Thanked
    Quote Originally Posted by KING View Post
    Stop FACKING SUMMONING ME TO THESE FUCKTARDS CONVOS.
    DAFUQ IS DIS FACKING SHYT.
    SHYT MAKES NO SENSE.

    On a side note. You fags are fucking hatting.
    You guys don't know shyt about spam.
    Danny would post on everysingle post every fucking hour, you couldnt tell which post was recent or anything. It was a fuck fest, he wouldnt have shyt to say....cares he posted like a fag he is.

    Josh made mutiple threads a day. And not just G, everywhere. That why everyone liked that dumb nikka.

    @Richard Nixon -Are you Endrat? @REAP @Digits2012 @Ghost -Son...I am dissapoint @Sjoerd -SMD @Canadian @FrosK -Dumb name is dumb @Nebulaa @That_Kid -Man Up @The XXX Devil -Oh look another joker avatar-how original and neat

    The rest who I didn't mention comment....Suck my left nut....but not to hard...it hurts.

  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