AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Passing string to CreateTimer Function (https://forums.alliedmods.net/showthread.php?t=317691)

marco811 07-24-2019 15:03

Passing string to CreateTimer Function
 
Hello. I have this error: error 035: argument type mismatch (argument 3)

I am trying to pass a string variable to the createTimer function.


Code:

new String:steamid[25];
       
if(GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid))) {
        CreateTimer(2.0, saveBan, steamid);
}

public Action saveBan(Handle timer, any steamid) {
.......
}

This method does not work either: (now this error: error 100: function prototypes do not match)

Not working:
Code:

public Action saveBan(Handle timer, char[] steamid) {
.........
}

Not working:
( error 100: function prototypes do not match)
Code:

public Action saveBan(Handle timer, const char[] steamid) {
........
}

What is the solution? I am confused! Thanks :wink:

Wyon 07-24-2019 15:25

Re: Passing string to CreateTimer Function
 
https://wiki.alliedmods.net/Timers_(...ng)#Data_Packs

Neuro Toxin 07-24-2019 16:30

Re: Passing string to CreateTimer Function
 
My question is why are you waiting 2 seconds to save a ban?

Sounds like an XY problem.

ddhoward 07-24-2019 23:00

Re: Passing string to CreateTimer Function
 
https://sm.alliedmods.net/new-api/timers/Timer

The second parameter must be any, Handle, or simply absent. Who told you that char[] would work?

Dragokas 07-30-2019 13:43

Re: Passing string to CreateTimer Function
 
You could use GetSteamAccountID (int) instead.

SpirT 08-05-2019 15:01

Re: Passing string to CreateTimer Function
 
It does not work because it needs to be:
PHP Code:

public Action TimerCallback(Handle timerHandle hndlany data*);

This is not neededjust use Handle timerHandle hndl
// any data is some info stored on the action you created the timer. 

Best Regards, Hope I could help you ;)

lugui 08-09-2019 08:13

Re: Passing string to CreateTimer Function
 
the prototype does not match, the function expects a variable, not a array

impossible_cc 08-09-2019 08:49

Re: Passing string to CreateTimer Function
 
Maybe there is more efficient method, but this should work

PHP Code:

#define STEAMID_CHARSTR_LENGTH 25

...(...)
{
    
char steamid[STEAMID_CHARSTR_LENGTH];
    if(
GetClientAuthId(clientAuthId_Steam2steamidsizeof(steamid))) 
    {
        
DataPack pack;
        
        
CreateDataTimer(2.0saveBanpack);
        
        for(
int i 0STEAMID_CHARSTR_LENGTH; ++i)
        {
            
pack.WriteCell(view_as<int>(steamid[i]));
        }
    }
}
public 
Action saveBan(Handle timerDataPack pack
{
    
pack.Reset();
    
char steamid[STEAMID_CHARSTR_LENGTH];
    for(
int i 0STEAMID_CHARSTR_LENGTH; ++i)
    {
        
steamid[i] = view_as<char>(pack.ReadCell());
    }
    
    
//done



asherkin 08-09-2019 18:16

Re: Passing string to CreateTimer Function
 
Quote:

Originally Posted by impossible_cc (Post 2662620)
Maybe there is more efficient method

https://sm.alliedmods.net/new-api/da...ck/WriteString


All times are GMT -4. The time now is 23:24.

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