Well have you ever seen code like this and thought wtf?
That is was I call a function pointer. It runs a function that is assigned to a variable. If you search through the game's files you will find this:
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 (tehehe, VB):
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:
Now my onPlayerSpawned looks like this:
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.
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.
What if I want to pass arguments through?
You pass your arguments through the pair of brackets before the semi-colon.
What if I want to thread the function pointer?
Simple, just add 'thread' before the variable.
Code:
[[level.callbackStartGameType]]();
That is was I call a function pointer. 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 (tehehe, 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]]();
}
}
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 function pointer?
Simple, just add 'thread' before the variable.
Code:
self thread [[self.byeCruelWorld]]();
A casual conversation between barata and I about Nukem.