[Help] Setting integer variable
#1

Hey,

I'm trying to change integer variable value from plugin,
Here the native:
Code:
native test(&int);
And the plugin codE:
Code:
cell AMX_NATIVE_CALL test(AMX* amx, cell* params)
{
	cell *dest = NULL;
    amx_GetAddr(amx,params[1],&dest);
    dest= (cell*)1;
    return 1;
}
Usage:
Code:
new
        inter;
    test(inter);
    
    printf("%d", inter);
But inter is still 0 (zero), but I changed him to 1 (one).
Why it's not working?




Update:
Fuck, Kyosaur you are awesome!
I found the answer in the plugin development tutorial:
Code:
//This function demonstrates: How to pass parameters by reference.
//PAWN native: native SetPawnReferenceVars(&value1, &Float:value2);
cell AMX_NATIVE_CALL SetPawnReferenceVars(AMX* amx, cell* params)
{
    const int val = 65;
    const float val2 = 84.54f;

    cell* addr[2] = {NULL, NULL};
    
    //Get the addresses of "value1" and "value2"
    amx_GetAddr(amx, params[1], &addr[0]);
    amx_GetAddr(amx, params[2], &addr[1]);

    //Dereference our pointers and assign our values. Remember to ALWAYS use the macro "amx_ftoc" to convert floats into 
    //cells (the appropriate float format for PAWN)!
    *addr[0] = val;
    *addr[1] = amx_ftoc(val2);

    return 1;
}


Update:
I trying to set string into array, like:
Code:
new array[32][32];
SetArray(array, sizeof(array));
But It setting the whole array, not array[idx],
Code i useD:
Code:
cell *arr = NULL;
amx_GetAddr(amx,params[2],&arr);

amx_SetString(&arr[0], "test0", 0, 0, strlen("test") + 1);
amx_SetString(&arr[1], "test1", 0, 0, strlen("test") + 1);
amx_SetString(&arr[2], "test2", 0, 0, strlen("test") + 1);
amx_SetString(&arr[3], "test3", 0, 0, strlen("test") + 1);
And I got:
Quote:

ttttest3

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)