AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Creating callbacks in Sourcepawn (https://forums.alliedmods.net/showthread.php?t=308732)

popey456963 07-01-2018 08:15

Creating callbacks in Sourcepawn
 
I'm trying to add a callback to a function I've designed which does some asynchronous actions. Using the example from Timers, I create a typedef:

HTML Code:

typeset ActionCallback {
  function void(float actions[2]);
}

And then I have a function attached to a methodmap which tries to call this "ActionCallback":

HTML Code:

  public void Save(ActionCallback callback) {
    int test[2];

    test[0] = 2;
    test[1] = 1;


    callback(test);
  }

Unfortunately, at the moment I'm getting a variety of errors that I have no idea how to solve. Namely:

C:\Users\\Documents\GitHub\ttt_sourcemod\rewr ite\includes\player_actions.inc(47) : error 012: invalid function call, not a valid address
C:\Users\\Documents\GitHub\ttt_sourcemod\rewr ite\includes\player_actions.inc(47) : warning 215: expression has no effect
C:\Users\\Documents\GitHub\ttt_sourcemod\rewr ite\includes\player_actions.inc(47) : error 001: expected token: ";", but found ")"
C:\Users\\Documents\GitHub\ttt_sourcemod\rewr ite\includes\player_actions.inc(47) : error 029: invalid expression, assumed zero
C:\Users\\Documents\GitHub\ttt_sourcemod\rewr ite\includes\player_actions.inc(47) : fatal error 190: too many error messages on one line

Does anyone know why my callback is not being identified as a function?

DJ Tsunami 07-01-2018 09:55

Re: Creating callbacks in Sourcepawn
 
I believe you have to invoke the callback like so:

PHP Code:

public void Save(ActionCallback callback) {
    
float test[2];

    
test[0] = 2.0;
    
test[1] = 1.0;

    
Call_StartFunction(INVALID_HANDLEcallback);
    
Call_PushArray(testsizeof(test));
    
Call_Finish();


INVALID_HANDLE indicates the callback is in the current plugin.

popey456963 07-11-2018 16:49

Re: Creating callbacks in Sourcepawn
 
Woah, thank you so much for the information. This worked :)


All times are GMT -4. The time now is 12:30.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.