SA-MP Forums Archive
y_va problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: y_va problem (/showthread.php?tid=520787)



y_va problem - KesaSport - 20.06.2014

pawn Код:
public OnGameModeInit()
{
        new Float:a = 6.3;
    new b = 5;
    new c[20] = "Labas";
    print(fmat("String = %s, Float = %.1f, Integer = %d", c, a, b));
        return true;
}
fmat(const fmat[], va_args<>)
{
    new msmg[145];
    va_format(msmg, sizeof (msmg), fmat, va_start<1>);
    return msmg;
}
Server log:
[13:53:20] [debug] Run time error 5: "Invalid memory access"
[13:53:20] [debug] AMX backtrace:
[13:53:20] [debug] #0 00027b4c in ?? (0x010ca830, 0x010d35a8, 0x010d35fc, 0x010d35f from ***.amx
[13:53:20] [debug] #1 00050aa8 in public SSCANF_OnGameModeInit () from ***.amx
[13:53:20] [debug] #2 00010550 in public Itter_OnGameModeInit () from ***.amx
[13:53:20] [debug] #3 native CallLocalFunction () [00472ad0] from samp-server.exe
[13:53:20] [debug] #4 0000de08 in ?? () from ***.amx
[13:53:20] [debug] #5 00005d48 in public ScriptInit_OnGameModeInit () from ****.amx
[13:53:20] [debug] #6 0000085c in public zcmd_OnGameModeInit () from ***.amx
[13:53:20] [debug] #7 native CallLocalFunction () [00472ad0] from samp-server.exe
[13:53:20] [debug] #8 00000350 in public OnGameModeInit () from ***.amx


Re : y_va problem - S4t3K - 20.06.2014

y_va isn't designed to do such things.
If you want to do it, use "format" directly. It will use the same part of memory than creating a variable in a function, formating it and returning it.

PHP код:

va_printEx
(const string[], va_args<>)
{
      new 
out[145];
      
va_format(outsizeof(out), stringva_start<1>);
      return print(
out);




Re: y_va problem - KesaSport - 20.06.2014

My code just example.


Re : y_va problem - S4t3K - 20.06.2014

And mine was an answer to the problem pointed out in the example.


Re: y_va problem - KesaSport - 20.06.2014

How to return string i some similar func?


Re : y_va problem - S4t3K - 20.06.2014

Use Slice's "sprintf" function.
It's in his "strlib" include.