Raised This Month: $32 Target: $400
 8% 

Solved Cannot coerce functions to values


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SHiva
Junior Member
Join Date: May 2016
Location: France
Old 02-20-2018 , 16:10   Cannot coerce functions to values
Reply With Quote #1

I got a problem with the compilation :



It's about this code :

Code:
typedef userMessage_BuildCallBack = function bool (int clientIndex, int argument, int drawCount, int drawDuration, char [] message, int length);
and

Code:
stock Handle:userMessage_MessageStructure_Add(  userMessages_MessageDisplayType:displayType,
                                                userMessage_BuildCallBack buildcallBack,
                                                int buildcallBackArgument,
                                                int repeatPeriod=0,
                                                int repeatCount=0,
                                                int minDisplayTime=0,
                                                int displayDelay=0,
                                                int flags=USER_MESSAGES_FLAG_NONE,
                                                int priority=50,
                                                int noRedisplayTime=0)
{
	
    Handle message = CreateArray(1, _:userMessage_MessageStructureElement_COUNT);
    
    SetArrayCell(message, _:userMessage_MessageStructureElement_DisplayType,           displayType);
    SetArrayCell(message, _:userMessage_MessageStructureElement_Flags,                 flags);
    SetArrayCell(message, _:userMessage_MessageStructureElement_BuildCallBack,         buildcallBack); // <---------- This is line 84
    SetArrayCell(message, _:userMessage_MessageStructureElement_BuildCallBackArgument, buildcallBackArgument);
    SetArrayCell(message, _:userMessage_MessageStructureElement_RepeatPeriod,          repeatPeriod);
    SetArrayCell(message, _:userMessage_MessageStructureElement_RepeatCount,           repeatCount);
    SetArrayCell(message, _:userMessage_MessageStructureElement_DisplayDuration,       minDisplayTime);
    SetArrayCell(message, _:userMessage_MessageStructureElement_DisplayDelay,          displayDelay);
    SetArrayCell(message, _:userMessage_MessageStructureElement_Priority,              priority);
    SetArrayCell(message, _:userMessage_MessageStructureElement_NoRedisplayTime,       noRedisplayTime);
    
    PushArrayCell(g_hUserMessages_MessagesArray, message);
    
    return message;
}
I know it's about the new syntax but don't know how to fix this. I am still learning about sourcepawn and I do not know how to use the function calls, someone to help me please ?

Last edited by SHiva; 02-21-2018 at 14:07.
SHiva is offline
_GamerX
AlliedModders Donor
Join Date: Jun 2011
Location: Fun Server
Old 02-20-2018 , 17:51   Re: Cannot coerce functions to values
Reply With Quote #2

PHP Code:
stock Handle userMessage_MessageStructure_Add(  userMessages_MessageDisplayType displayType,
                                                
userMessage_BuildCallBack buildcallBack,
                                                
int buildcallBackArgument,
                                                
int repeatPeriod=0,
                                                
int repeatCount=0,
                                                
int minDisplayTime=0,
                                                
int displayDelay=0,
                                                
int flags=USER_MESSAGES_FLAG_NONE,
                                                
int priority=50,
                                                
int noRedisplayTime=0)
{
    
    
Handle message CreateArray(1_:userMessage_MessageStructureElement_COUNT);
    
    
SetArrayCell(message_:userMessage_MessageStructureElement_DisplayType,           displayType);
    
SetArrayCell(message_:userMessage_MessageStructureElement_Flags,                 flags);
    
SetArrayCell(message_:userMessage_MessageStructureElement_BuildCallBack,         buildcallBack);
    
SetArrayCell(message_:userMessage_MessageStructureElement_BuildCallBackArgumentbuildcallBackArgument);
    
SetArrayCell(message_:userMessage_MessageStructureElement_RepeatPeriod,          repeatPeriod);
    
SetArrayCell(message_:userMessage_MessageStructureElement_RepeatCount,           repeatCount);
    
SetArrayCell(message_:userMessage_MessageStructureElement_DisplayDuration,       minDisplayTime);
    
SetArrayCell(message_:userMessage_MessageStructureElement_DisplayDelay,          displayDelay);
    
SetArrayCell(message_:userMessage_MessageStructureElement_Priority,              priority);
    
SetArrayCell(message_:userMessage_MessageStructureElement_NoRedisplayTime,       noRedisplayTime);
    
    
PushArrayCell(g_hUserMessages_MessagesArraymessage);
    
    return 
message;

__________________

Last edited by _GamerX; 02-20-2018 at 17:55.
_GamerX is offline
Send a message via ICQ to _GamerX Send a message via Skype™ to _GamerX
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-20-2018 , 21:28   Re: Cannot coerce functions to values
Reply With Quote #3

As the error states, you can't directly pass in a function to something that expects a non-function value anymore (any doesn't include functions). You're trying to pass in a callback into SetArrayCell.

Given your current code, the easiest workaround would be to wrap the entire buildcallBack argument as a private forward like so:

Code:
// userMessage_MessageStructure_Add
Handle callbackForward = CreateForward(ET_Single, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_cell);

AddToForward(callbackForward, buildcallBack);

// use Call_StartForward and make sure to clean it up when you're done
The other option is to use DataPacks instead, but you'd have to rewrite a lot more.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
SHiva
Junior Member
Join Date: May 2016
Location: France
Old 02-21-2018 , 06:36   Re: Cannot coerce functions to values
Reply With Quote #4

It seems hard to use for this plugin, I don't fully understand how forwards and native works.

it's not my plugin it's about. This is H3bus DM Plugin for CS:GO and i'm trying to update its syntax to be able to compile it with sourcemod 1.8. But there is so much module on this plugin that i don't know where to start using forwards for this case.

It does not matter, I will first try to understand before throwing myself in. By the way, Thank you for you help

Last edited by SHiva; 02-21-2018 at 07:01.
SHiva is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 02-21-2018 , 10:30   Re: Cannot coerce functions to values
Reply With Quote #5

Like nosoop mentioned, the other option is to use DataPacks which have a WriteFunction method for adding/removing function pointers.
hmmmmm is offline
SHiva
Junior Member
Join Date: May 2016
Location: France
Old 02-21-2018 , 13:00   Re: Cannot coerce functions to values
Reply With Quote #6

Quote:
Originally Posted by hmmmmm View Post
Like nosoop mentioned, the other option is to use DataPacks which have a WriteFunction method for adding/removing function pointers.
Yeah, finally thank you, I managed to solve the problem with DataPacks. The problem was mostly to find all the functions that used message as an array with GetArrayCell and replace it with ReadPackCell.

Now i got an other problem but is no longer this case, thank you all for your help !
SHiva is offline
Reply



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 00:29.


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