Jump to content

Question from Pawn scripter


s2sk

Recommended Posts

Hi.

I have 2 problem. In Pawn (sa-mp hello) i can write

stock Function(value1, value2 = 5, value3 = 10) // value2 and value3 optional parameters

{

return 1;

}

 

how make it in Lua (i talking about optional parameters)?

 

if make so

function Function(value1, value2 = 5, value3 = 10)
{
}

i have error from interpreter

 

and more question... how skip argument?

 

again in Pawn i can write

stock Function(value1, value2 = 5, value = 10)

{

return 1;
}



public OnPlayerConnect(playerid)
{

Function(value1, .value3 = 20); // <<<----------- skip value2 
}

 

how make it on Lua?

 

thx.

Link to comment
  • Discord Moderators

You can use everything actually instead of value, I mean every false condition(so only nil and false and _(this is called a dummy variable, and its always a nil value))
 

Link to comment
  • Moderators

A underline makes sense, because people understand that it means that the parameter has no purpose. But it is technically not skipping, as the underline is a variable after all.

It just depends how you want to pass that information into the function.

 

A single parameter that contains a table with multiple values works sometimes even better, because you can use it as an array(similar to parameters in a way) as well as an object.

Edited by IIYAMA
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...