stock vs function
#1

whats the difference between

PHP код:
stock GetTruckNeedTracks(playerid)
{
    new 
truckneedtracks;
    new 
truckskill GetPlayerTruckSkill(playerid);
    if(
truckskill == 1truckneedtracks 35;
    else if(
truckskill == 2truckneedtracks 100;
    else if(
truckskill == 3truckneedtracks 220;
    else if(
truckskill == 4truckneedtracks 450;
    return 
truckneedtracks;

and

PHP код:
function GetTruckNeedTracks(playerid)
{
    new 
truckneedtracks;
    new 
truckskill GetPlayerTruckSkill(playerid);
    if(
truckskill == 1truckneedtracks 35;
    else if(
truckskill == 2truckneedtracks 100;
    else if(
truckskill == 3truckneedtracks 220;
    else if(
truckskill == 4truckneedtracks 450;
    return 
truckneedtracks;

which one should i use?
Reply
#2

the keyword function doesn't exists, read this

https://sampwiki.blast.hk/wiki/Stock#stock
Reply
#3

You may also consider taking a look at this tutorial by Vince.
Reply
#4

by function i meant
PHP код:
#define function%0(%1) forward %0(%1); public %0(%1) // Shortcut 
ni this case i should use function instead of stock?
Reply
#5

There are three (simplified) scenarios:
1. You need a callback, or the function is called by a timer: use forward + public
2. You write a function in your gamemode. Do not use anything! Just write:
pawn Код:
GetTruckNeedTracks(playerid)
{
    new truckneedtracks;
    new truckskill = GetPlayerTruckSkill(playerid);
    if(truckskill == 1) truckneedtracks = 35;
    else if(truckskill == 2) truckneedtracks = 100;
    else if(truckskill == 3) truckneedtracks = 220;
    else if(truckskill == 4) truckneedtracks = 450;
    return truckneedtracks;
}
3. You are writing an include. Use stock.
Reply
#6

and whats the difference?they both work,is it more optimized,less memory used or..what?
Reply
#7

stock simple removes the variable / function from your code if not used at compilation, it could lead to useless code fragments in your code because the unused warning doesn't appear
a public variable / function instead is always included in your code even if not directly used, it also needs space in the header (it stores the address and the name)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)