Raised This Month: $51 Target: $400
 12% 

Prototypes error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-17-2016 , 13:22   Prototypes error
Reply With Quote #1

Why do I get this error:
Code:
error 100: function prototypes do not match.
while compiling this code:
PHP Code:
DataPack entityInfo;    
    
    
entityInfo.WriteCell(entity);
    
    
CreateDataTimer(15.0Timer_EntityentityInfo); 
Even tho the CreateDataTimer function accepts any value:
PHP Code:
/**
 * Creates a basic timer.  Calling CloseHandle() on a timer will end the timer.
 *
 * @param interval            Interval from the current game time to execute the given function.
 * @param func                Function to execute once the given interval has elapsed.
 * @param data                Handle or value to pass through to the timer callback function.
 * @param flags                Flags to set (such as repeatability or auto-Handle closing).
 * @return                    Handle to the timer object.  You do not need to call CloseHandle().
 *                            If the timer could not be created, INVALID_HANDLE will be returned.
 */
native Handle:CreateTimer(Float:intervalTimer:funcany:data=INVALID_HANDLEflags=0);

/**
 * Creates a timer associated with a new datapack, and returns the datapack.
 * @note The datapack is automatically freed when the timer ends.
 * @note The position of the datapack is not reset or changed for the timer function.
 *
 * @param interval            Interval from the current game time to execute the given function.
 * @param func                Function to execute once the given interval has elapsed.
 * @param datapack            The newly created datapack is passed though this by-reference 
 *                            parameter to the timer callback function.
 * @param flags                Timer flags.
 * @return                    Handle to the timer object.  You do not need to call CloseHandle().
 */
stock Handle:CreateDataTimer(Float:intervalTimer:func, &Handle:datapackflags=0)
{
    
datapack CreateDataPack();
    
flags |= TIMER_DATA_HNDL_CLOSE;
    return 
CreateTimer(intervalfuncdatapackflags);

btw, I dont want to use the old SP style, I'm trying to use the new style only because it's more like C/C++, thanks!

EDIT: I tried with CreateTimer, same results
PHP Code:
CreateTimer(15.0Timer_EntityentityInfoTIMER_DATA_HNDL_CLOSE); 

Last edited by TheDS1337; 01-17-2016 at 13:26.
TheDS1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-17-2016 , 13:33   Re: Prototypes error
Reply With Quote #2

I guess it's not Create[Data]Timer, but Timer_Entity function that's causing errors. What's the prototype of Timer_Entity function?
klippy is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-17-2016 , 13:39   Re: Prototypes error
Reply With Quote #3

Quote:
Originally Posted by KliPPy View Post
I guess it's not Create[Data]Timer, but Timer_Entity function that's causing errors. What's the prototype of Timer_Entity function?
It's like this:
PHP Code:
public Action Timer_Entity(Timer timerDataPack entityInfo
TheDS1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-17-2016 , 13:45   Re: Prototypes error
Reply With Quote #4

Not 100% sure how typesets work (never written a SourceMod plugin), but looks like you will have to do:
PHP Code:
public Action Timer_Entity(Handle timerHandle entityInfo
then cast entityInfo to a DataPack handle.

Last edited by klippy; 01-17-2016 at 13:45.
klippy is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-17-2016 , 13:48   Re: Prototypes error
Reply With Quote #5

Quote:
Originally Posted by KliPPy View Post
Not 100% sure how typesets work (never written a SourceMod plugin), but looks like you will have to do:
PHP Code:
public Action Timer_Entity(Handle timerHandle entityInfo
then cast entityInfo to a DataPack handle.
Yes tried this and it worked, btw why you used Handle instead of Timer ? is it because Timer isn't a methodmap (I thought it was methodmap, looked into the include and saw that it's a typeset).

and btw can I still use other methodmaps instead of using Handle ? one more thing, will DataPack entityInfo get created ? because when I used entityInfo.DataPack() I got an error.
TheDS1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-17-2016 , 13:57   Re: Prototypes error
Reply With Quote #6

Right, Timer isn't a methodmap, but a typeset - it just specifies the function prototype. Think of it as delegates in C#. If you look at CreateTimer prototype, it looks like:
PHP Code:
native Handle:CreateTimer(Float:intervalTimer:funcany:data=INVALID_HANDLEflags=0); 
meaning that only a function that complies with Timer typeset can be passed in as a second argument.
The Timer typeset specifies one of its prototypes as:
PHP Code:
function Action(Handle timerHandle hndl); 
As you can see, timer is of type Handle. Second parameter is also of type Handle, but I am not sure how strict typesets are - could it just be a DataPack instead? If not, you could probably cast it with
PHP Code:
DataPack myDataPack view_as<DataPack>(hndl); 
klippy is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-17-2016 , 13:59   Re: Prototypes error
Reply With Quote #7

Thank you sir! what about the entityInfo.DataPack() instead of entityInfo = CreateDataPack(); ?
TheDS1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-17-2016 , 14:09   Re: Prototypes error
Reply With Quote #8

Not sure about what you are asking, but entityInfo.DataPack() doesn't even seem like a valid thing to do (DataPack() is a constructor I believe). To create a DataPack I believe you would either do
PHP Code:
DataPack dp = new DataPack(); 
or
PHP Code:
DataPack dp CreateDataPack(); 
And also, you don't have to create a datapack if you use CreateDataTimer(), it will do it automagically for you and byref it back to you: https://github.com/alliedmodders/sou...imers.inc#L206.

Last edited by klippy; 01-17-2016 at 14:09.
klippy is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-17-2016 , 14:13   Re: Prototypes error
Reply With Quote #9

Lol, I forgot that too wtf XD, thanks for reminding
TheDS1337 is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 01-17-2016 , 15:12   Re: Prototypes error
Reply With Quote #10

I should note, CreateDataTimer creates a DataPack handle for you and sends it off to the timer and once the function is over, the variable you passed for the datapack param is giving said handle that you do the WriteCell on(after CreateDataTimer execution).

Klippy, typeset is similar in funcnum.
WildCard65 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 08:22.


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