Invalid variable values
#1

Hello,

I am having a conflict with variables being assigned (or that is the only thing I can figure). As the script below shows, I'm creating a variable and assigning the value of "1" to it. Inside the OnFilterScriptInit function, I call a custom function, LoadMap, which gets passed that variable. All the function does it print the variable, so it would be expected to print the value "1". However, it prints a value of "109" for me. Here is the script:
pawn Код:
#include    <a_samp>


new
    g_CurMap = 1;


public OnFilterScriptInit()
{
    LoadMap(g_CurMap);
    return 1;
}

stock LoadMap(mapID)
{
    printf("mapID: %i", mapID);
}
I'm assuming there is a problem with memory of the script, however am not sure. I've been screwing around for the past hour or so trying to isolate the problem, and came across something interesting. It seems calling the printf() function before calling LoadMap, it will pass the correct value of 1. Here is the script, which prints the expected result:
pawn Код:
#include    <a_samp>


new
    g_CurMap = 1;


public OnFilterScriptInit()
{
    printf("g_CurMap: %i", g_CurMap);
    LoadMap(g_CurMap);
    return 1;
}

stock LoadMap(mapID)
{
    printf("mapID: %i", mapID);
}
Can anyone give me a reason as to why this is happening? I tried using different functions before the LoadMap function as well, but that did not fix the problem either. I suppose only functions that use the variable prior to passing it to LoadMap would fix this issue but have not tested it. My brother had a similar problem quite some time ago (memory of variables getting incorrectly assigned due to function call (assuming that is the problem), which was caused by strcat) and he never got a solution to it.

Thanks.
Reply


Messages In This Thread
Invalid variable values - by Bakr - 28.11.2012, 18:46
Re: Invalid variable values - by Vince - 28.11.2012, 18:53
Re: Invalid variable values - by Bakr - 28.11.2012, 19:02
Re: Invalid variable values - by [KHK]Khalid - 28.11.2012, 19:07
Re: Invalid variable values - by Bakr - 28.11.2012, 19:11
Re: Invalid variable values - by Bakr - 29.11.2012, 18:42
AW: Invalid variable values - by Nero_3D - 08.12.2012, 10:30
Re: AW: Invalid variable values - by Bakr - 09.12.2012, 22:30
AW: Re: AW: Invalid variable values - by Nero_3D - 14.12.2012, 17:17
Re: Invalid variable values - by Bakr - 16.01.2013, 20:49

Forum Jump:


Users browsing this thread: 1 Guest(s)