AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Problem with DataPacks (https://forums.alliedmods.net/showthread.php?t=259269)

8guawong 03-03-2015 22:05

Problem with DataPacks
 
PHP Code:

public MenuHandler(Handle:menuMenuAction:actionparam1param2)
{
    if (
action == MenuAction_Select)
    {
        new 
Handle:data CreateDataPack();
        
WritePackCell(dataparam1);
        
SQL_TQuery(dbCheckDB "some query"data);
    }
}

public 
CheckDB (Handle:ownerHandle:hndl, const String:error[], any:data)
{
    new 
client ReadPackCell(data);
    
PrintToChat(data"test");



Code:

[SM] Native "PrintToChat" reported: Client index 431227078 is invalid
Why? How to fix?

crap nvm i was using wrong variable :D

WildCard65 03-03-2015 22:19

Re: Problem with DataPacks
 
you forgot to reset the pack. Also your passing a handle to a native expecting client index, I'm assuming you meant to use the variable client instead of data.

Drixevel 03-04-2015 00:45

Re: Problem with DataPacks
 
Quote:

Originally Posted by 8guawong (Post 2269325)
PHP Code:

public MenuHandler(Handle:menuMenuAction:actionparam1param2)
{
    if (
action == MenuAction_Select)
    {
        new 
Handle:data CreateDataPack();
        
WritePackCell(dataparam1);
        
SQL_TQuery(dbCheckDB "some query"data);
    }
}

public 
CheckDB (Handle:ownerHandle:hndl, const String:error[], any:data)
{
    new 
client ReadPackCell(data);
    
PrintToChat(data"test");



Code:

[SM] Native "PrintToChat" reported: Client index 431227078 is invalid
Why? How to fix?

crap nvm i was using wrong variable :D

Here's how to fix that issue:
Code:

public MenuHandler(Handle:menu, MenuAction:action, param1, param2)
{
        if (action == MenuAction_Select)
        {
                new Handle:data = CreateDataPack();
                WritePackCell(data, GetClientUserId(param1));
                SQL_TQuery(db, CheckDB "some query", data);
        }
}

public CheckDB (Handle:owner, Handle:hndl, const String:error[], any:data)
{
        ResetPack(data);
        new client = GetClientOfUserId(ReadPackCell(data));
        CloseHandle(data);
        PrintToChat(client, "test");
}

IF that's the only variable you're wanting to pass through, just pass that alone: (You probably already know this but It can help others)
Code:

public MenuHandler(Handle:menu, MenuAction:action, param1, param2)
{
        if (action == MenuAction_Select)
        {
                SQL_TQuery(db, CheckDB "some query", GetClientUserid(param1));
        }
}

public CheckDB (Handle:owner, Handle:hndl, const String:error[], any:data)
{
        new client = GetClientOfUserId(data);
        PrintToChat(client, "test");
}


Powerlord 03-04-2015 00:49

Re: Problem with DataPacks
 
As a general rule, I do ResetPack as soon as I write the last data value. That way, even if you forget to ResetPack before reading, you've already reset it.

8guawong 03-04-2015 00:54

Re: Problem with DataPacks
 
Quote:

Originally Posted by r3dw3r3w0lf (Post 2269352)
Here's how to fix that issue:
Code:

public MenuHandler(Handle:menu, MenuAction:action, param1, param2)
{
        if (action == MenuAction_Select)
        {
                new Handle:data = CreateDataPack();
                WritePackCell(data, GetClientUserId(param1));
                SQL_TQuery(db, CheckDB "some query", data);
        }
}

public CheckDB (Handle:owner, Handle:hndl, const String:error[], any:data)
{
        ResetPack(data);
        new client = GetClientOfUserId(ReadPackCell(data));
        CloseHandle(data);
        PrintToChat(client, "test");
}

IF that's the only variable you're wanting to pass through, just pass that alone: (You probably already know this but It can help others)
Code:

public MenuHandler(Handle:menu, MenuAction:action, param1, param2)
{
        if (action == MenuAction_Select)
        {
                SQL_TQuery(db, CheckDB "some query", GetClientUserid(param1));
        }
}

public CheckDB (Handle:owner, Handle:hndl, const String:error[], any:data)
{
        new client = GetClientOfUserId(data);
        PrintToChat(client, "test");
}


param1 is client already :wink:

Drixevel 03-04-2015 01:58

Re: Problem with DataPacks
 
Quote:

Originally Posted by 8guawong (Post 2269355)
param1 is client already :wink:

During a Threaded Query, the response time isn't instant so in that situation, It's best to get the client user ID and and revert it back on the other end just in case the client disconnects during the query.

8guawong 03-04-2015 02:50

Re: Problem with DataPacks
 
Quote:

Originally Posted by r3dw3r3w0lf (Post 2269375)
During a Threaded Query, the response time isn't instant so in that situation, It's best to get the client user ID and and revert it back on the other end just in case the client disconnects during the query.

oh ok i'll change it just incase , thanks!


All times are GMT -4. The time now is 03:04.

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