How to add arguments to format?
#1

For example:
pawn Код:
for(new i; i<5; i++)
{
    CallLocalFunction(something, something, something[i]);
}
It works but it calls the function 5x. I want to call once...
Is this possible?
Reply
#2

What do you mean? Explain clearly.
Reply
#3

pawn Код:
CallLocalFunction(func, parameters, cmd[0], cmd[1], cmd[2]); // I defined func and parameters before
Like this. But the number of cmd is various.
Reply
#4

Did you copy this from somewhere? This is your code:

pawn Код:
for(new i; i < [B]5[/B]; i++)
It tells the script, that it should call the function AS long, as i is smaller then 5 times. That means:
0, 1, 2, 3, 4 = 5 TIMES

If you want it for one time, it should be like this:

pawn Код:
for(new i; i < 1; i++)
Reply
#5

I didn't copy it, and your code will add one parameter. I want more...
Reply
#6

This may be what you're looking for, I'm not sure: https://sampforum.blast.hk/showthread.php?tid=77000
Reply
#7

Yes thanks

Quote:
Originally Posted by MP2
Посмотреть сообщение
This may be what you're looking for, I'm not sure: https://sampforum.blast.hk/showthread.php?tid=77000
But, there's any function to get an other function's arguments?
Reply
#8

Quote:
Originally Posted by Twisted_Insane
Посмотреть сообщение
Did you copy this from somewhere? This is your code:

pawn Код:
for(new i; i < [B]5[/B]; i++)
It tells the script, that it should call the function AS long, as i is smaller then 5 times. That means:
0, 1, 2, 3, 4 = 5 TIMES

If you want it for one time, it should be like this:

pawn Код:
for(new i; i < 1; i++)
Err, you know if your calling a function once, there is no need for a loop?
Reply
#9

Wrote an example, similar to RyDeR` code

pawn Код:
public OnFilterScriptInit() {
    CallLocalFunction("MiscFunc", "ii", 1, 2); // to init CallLocalFunction
    CallLocalFunctionEx("MyFunc", "iiiii", 1, 2, 3, 4, 5);
}
pawn Код:
stock CallLocalFunctionEx(const func[], const form[], {Float, _}: ...) {
    new
        args = ((numargs() - 2) << 2),
        addr,
        i
    ;
    #emit addr.pri form
    #emit stor.s.pri addr

    for(i = (addr + args), args += 8; addr != i; i -= 4) {
        #emit load.s.pri i
        #emit load.i
        #emit push.pri
    }
    #emit push.s form
    #emit push.s func
    #emit push.s args
    #emit sysreq.c CallLocalFunction
}
pawn Код:
forward MyFunc(v1, v2, v3, v4, v5);
public MyFunc(v1, v2, v3, v4, v5) {
    printf("%d %d %d %d %d", v1, v2, v3, v4, v5);
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)