HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How do you use natives?

08-19-2006, 10:37 PM#1
darkwulfv
I feel so stupid asking this, but I'll do it anyways. I hear about natives everywhere. My problem is, how do you use them? When I was flipping through JASScraft, I decided to look at some natives, so I looked at
"CreateNUnitsAtLoc" This is what it showed me:
Collapse JASS:
function CreateNUnitsAtLoc takes integer count, integer unitId, player whichPlayer, location loc, real face returns group
    call GroupClear(bj_lastCreatedGroup)
    loop
        set count = count - 1
        exitwhen count < 0
        call CreateUnitAtLocSaveLast(whichPlayer, unitId, loc, face)
        call GroupAddUnit(bj_lastCreatedGroup, bj_lastCreatedUnit)
    endloop
    return bj_lastCreatedGroup
endfunction

So what does that mean? Is it just saying what the native "CreateNUnitsAtLoc" does? Do I need to put this into my code, or just "CreateNUnitsAtLoc"?
08-19-2006, 11:03 PM#2
Razernok
use
Collapse JASS:
call CreateNUnitsAtLoc(count, unitId, whichPlayer, loc, face)
or
(for those with a return like the previous one)
Collapse JASS:
local group g

set g = CreateNUnitsAtLoc(count, unitId, whichPlayer, loc, face)
08-19-2006, 11:06 PM#3
iNfraNe
CreateNUnitAtLoc isnt a native. It is a blizzard.j (referred to as BJ) function.

The natives for creating a unit are:

Collapse JASS:
native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit
native CreateUnitAtLoc takes player id, integer unitid, location whichLocation, real face returns unit
native CreateUnitAtLocByName takes player id, string unitname, location whichLocation, real face returns unit
native CreateUnitByName takes player whichPlayer, string unitname, real x, real y, real face returns unit
08-19-2006, 11:29 PM#4
Razernok
but don't you call them like you do a function?
08-20-2006, 12:06 AM#5
Alevice
Yes you do. The only (valuable) difference between the native function and any non-native function is that the natives are directly called from the game engine, which mean its execution is much faster.
08-20-2006, 12:40 AM#6
Razernok
looking on jass manual, it appears all functions are natives.
08-20-2006, 12:43 AM#7
iNfraNe
That would be wrong. Only functions in common.j are natives.
08-20-2006, 12:44 AM#8
Vexorian
natives are declared in common.j

some functions are declared in blizzard.j

the rest in your map.
08-20-2006, 12:51 AM#9
Razernok
Quote:
Originally Posted by Vexorian
natives are declared in common.j

some functions are declared in blizzard.j

the rest in your map.
so functions in your map are also consider as natives?
I thought they were just functions not natives.
08-20-2006, 01:01 AM#10
Vexorian
Natives are functions, the difference is that they are hard coded in the game engine.

The rest we call functions , are JASS functions declared by either blizzard (in blizzard.j) generated by world editor or wrote by users
08-20-2006, 01:33 AM#11
Razernok
ahh, i see now.
08-20-2006, 03:38 AM#12
darkwulfv
uhh no questions were answered, im sorry...
I mean, how do you use a native? Do you just put in the line with all the takes and returns, or do you put in the function? Thats my question, becuase everytime I show a trigger here, someone tells me to use natives, but I don't know how to:
1. find the natives of BJ's
2. how to put them in.

I guess thats what I was asking.
08-20-2006, 04:11 AM#13
wonder_priest
All BJ functions call at least one native function. To find the native, and skip using the BJ, use JassCraft or something, and spot the native inside the BJ function.

For example, here is a BJ function:
Collapse JASS:
function DisplayTextToForce takes force toForce, string message returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), toForce)) then
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, message) //This text is red!
    endif
endfunction
The red text marks the native function call:
Collapse JASS:
DisplayTextToPlayer takes player toPlayer, real x, real y, string message returns nothing
See the difference? A native does not use any other function calls, it just takes parameters and executes the code that is hard-coded into the engine.

Use a native the same way you would use a BJ function.
Collapse JASS:
call DisplayTextToForce(...) BJ function
call DisplayTextToPlayer(...) Native function

EDIT: Dang! You can't format text inside JASS tags :(
08-20-2006, 04:14 AM#14
Alevice
Quote:
uhh no questions were answered, im sorry...

Razernok's first ost in this thread should have answered all your needs.
08-20-2006, 04:31 AM#15
PipeDream
Quote:
All BJ functions call at least one native function.
There are some that call only other BJ functions and some that call nothing, like GetLastCreatedUnit()
Not that this changes anything.