AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Prototypes error (https://forums.alliedmods.net/showthread.php?t=277826)

TheDS1337 01-17-2016 13:22

Prototypes error
 
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); 


klippy 01-17-2016 13:33

Re: Prototypes error
 
I guess it's not Create[Data]Timer, but Timer_Entity function that's causing errors. What's the prototype of Timer_Entity function?

TheDS1337 01-17-2016 13:39

Re: Prototypes error
 
Quote:

Originally Posted by KliPPy (Post 2384114)
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


klippy 01-17-2016 13:45

Re: Prototypes error
 
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.

TheDS1337 01-17-2016 13:48

Re: Prototypes error
 
Quote:

Originally Posted by KliPPy (Post 2384121)
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.

klippy 01-17-2016 13:57

Re: Prototypes error
 
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); 


TheDS1337 01-17-2016 13:59

Re: Prototypes error
 
Thank you sir! what about the entityInfo.DataPack() instead of entityInfo = CreateDataPack(); ?

klippy 01-17-2016 14:09

Re: Prototypes error
 
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.

TheDS1337 01-17-2016 14:13

Re: Prototypes error
 
Lol, I forgot that too wtf XD, thanks for reminding :)

WildCard65 01-17-2016 15:12

Re: Prototypes error
 
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.


All times are GMT -4. The time now is 08:50.

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