y_va problem
#1

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
Reply
#2

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);

Reply
#3

My code just example.
Reply
#4

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

How to return string i some similar func?
Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)