Raised This Month: $64 Target: $400
 16% 

Creating callbacks in Sourcepawn


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
popey456963
Member
Join Date: Mar 2016
Old 07-01-2018 , 09:15   Creating callbacks in Sourcepawn
Reply With Quote #1

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?
popey456963 is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 07-01-2018 , 10:55   Re: Creating callbacks in Sourcepawn
Reply With Quote #2

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.
__________________
DJ Tsunami is offline
popey456963
Member
Join Date: Mar 2016
Old 07-11-2018 , 17:49   Re: Creating callbacks in Sourcepawn
Reply With Quote #3

Woah, thank you so much for the information. This worked
popey456963 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:39.


Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode