• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

jass basic question 2

Status
Not open for further replies.
im still reading http://www.hiveworkshop.com/forums/...als-280/beginning-jass-tutorial-series-30765/

and i got afew more questions to ask :D (btw i dont know how 2 quote jass like with the white box so if some1 can tell me how 2 do that would be great. Rite know i'll just use normal quote)

1)
function variable_test takes nothing returns nothing
local unit u
set u = CreateUnit(…..) //Creates a unit and sets the variable to it
I asked about this in the last thread. I checked the *createunit* uhm... function (i think function is the word refering this code/command correct me if im wrong) and it says i need "takes player id, integer unitid, real x, real y, real face returns unit"
so im guessing:
-take player id- is player number? (like i put *1,* here and will create a unit for player one)
-integer unitid- is the id of the unit? (like for pally is Hpal?, so in here i enter *Hpal,*? but its a integer shouldn't i enter a number instead?)
-real x- i have no idea what this is... since its a real, i assume i enter a number here, but what does this number do?
-real y- same with real x... no idea what this is
-real face- lol no idea what this is either
is this correct? lol

2)
Hey wait! I want the value to change, does that mean I need a new variable?
-No, not necessarily. All you need to do is put “set your_variable = newvalue
Here’s an example.

function variable takes nothing returns nothing
local unit u = CreateUnit(…)
//Other actions
set u = other_unit //other_unit would be some other unit, don't use this example literally!
endfunction

Remember though, that old value isn’t set to that variable, so if you want 2 different units, use 2 different variables.
i dont understand the purpose of this part ... what does the author mean by *new variable*? ...
the way i see it it's like uhm ...
-create a unit (…), name it *u*
-and ... (on the line start with set u = ...) u nolonger is this unit created with function *createunit* with the identity of *…* and ... *u* turns into *other_unit* ...
i assume this *other_unit* is like another *createunit* with a different identity like *createunit(῵ <---different number) ... rite? no? am it way off lol?

3)
Ok, so I have my local variable. Now what?
-Now, use it! Here’s an example.

function KillUnit takes unit u returns nothing
-If you notice, KillUnit needs a unit. Now, you can fill this with many things, like GetTriggerUnit(), GetSpellAbilityUnit(), or any function which returns a unit. However, a variable can be a unit, so you can put that there instead. Here’s a side-by-side comparison.

so uhm... is *function killunit takes unit u returns nothing* part of the function of the variable?
as in the function;
function variable_test takes nothing returns nothing
local unit u
set u = CreateUnit(…..)
endfunction
? or is it a different function? ... and the next example the author gives:

function variable_testA takes nothing returns nothing
local unit u = GetTriggerUnit()
call KillUnit(u)
endfunction

function variable_testB takes nothing returns nothing
call KillUnit(GetTriggerUnit())
endfunction
doesn't have anything in the variable function ... so how does This function *use* the variable function? since i dont see any connection between the 2 ... or is the author making a completely different example?

ty in advance :D
 
Level 10
Joined
Sep 21, 2007
Messages
517
the two functions dont relate, the only relation they have is that they both use the triggering unit as the unit being killed.

as for the real x, real y, etc... they are the name of the parameters you are going to input in the functions, nothing more. but as you can see they also define the type of parameter you are allowed to put in, REAL x, REAL y etc, by face they mean the degrees the unit should face, aint so clear ey? Gl in learning jass bro
 
Level 4
Joined
Dec 9, 2008
Messages
52
Part 1:

Player ID isn't a number, it's a playerid. To turn a number into a player id you use the function Player(). So putting in Player(0) or Player(1) returns player 1 and player 2 respectively (jass starts at 0, gui starts at 1 =\)

Integer UnitID is an integer, but it's weird. It's basically a huge number that you access w/ single quotes. So 'hfoo' is the number of a footman. If you convert that number to decimal it's like 324235151523525. You were on the right track.

Real X is the x location of the unit. The center of the map is 0, the right of the map is in the positives, the left of the map is in negatives

Real Y is the y location of the unit. The center of the map is 0. The top is in the positives, the bottom is inthe negatives.

Real face is the direction the unit is facing. It uses degrees so any real number between 0 and 360 will work. 0 makes it face east, 90 north etc.

Part 2: i'll get to later...
 
Integer UnitID is an integer, but it's weird. It's basically a huge number that you access w/ single quotes. So 'hfoo' is the number of a footman. If you convert that number to decimal it's like 324235151523525. You were on the right track.

i dont understand what you mean by "hfoo" is a number ... its letters lol?
and ... you said you convert it into decimal? so ... this number can't be bigger than zero? ... like 0.3834474939? and how do i turn letters into number :3

Real X is the x location of the unit. The center of the map is 0, the right of the map is in the positives, the left of the map is in negatives

Real Y is the y location of the unit. The center of the map is 0. The top is in the positives, the bottom is inthe negatives.

so uhm... does this has any connection with me creating a region on the world editor? ... and how do i check where is what (x,y) value?

Part 2: i'll get to later...
<---lol
but ty :3
 
and monkie crew, if u want any help with learning JASS, il help, since most of these tutorials cause headaches and are, Crap :p

i woulnd't call all the tutorials *craps* since they're labor of love ... or something of that nature ... but thats beside the point ...
and yeah it is kindda confusing without some1 answering my questions ... i read the turtorial a couple times (only lesson 1-3) and my brain hurts alot :S
 
Level 11
Joined
Feb 22, 2006
Messages
752
Use [/code] and
JASS:
 for jass scripts (the [code=jass] goes first, I just reversed the order so the system doesn't parse the tags):

[code=jass]
function foo takes nothing returns nothing
endfunction

Use [/icode] and (those r lowercase L's before jass) to do inline jass code: [icode=jass]function foo takes nothing returns nothing


Number 1 seems to have already been answered, so I'll skip to number 2:

Variables hold arbitrary data. So a unit variable named u can hold a single unit. It can be any unit, as long as that unit exists. These variables can be redefined any number of times so that they hold different data. So basically the author was saying that if you wanted to keep track of another unit you could set u equal to the second unit instead of creating a second unit variable. Of course, if you want to keep track of two units at the same time you would need 2 unit variables because one variable can only hold one piece of data at a time, so one unit variable can only hold one unit at a time.

Number 3:

KillUnit() is just an example function the author is using. It's a native function (one that has already been written by blizzard) that kills a unit. The author is using it to illustrate how to use local variables. You seem to have the wrong idea about variables and functions. Variables and functions are two completely different things. You don't necessarily need one to have the other. However, in most cases functions will use variables to keep track of data and sometimes you need a function to set a variable equal to something:

JASS:
local unit u = CreateUnit(Player(0), 'hfoo', 0, 0, 0)

The function CreateUnit() creates a unit and returns the unit that was created, which is why you can use it to set a unit variable (in this case u) equal to something. There are other functions that return a unit, and you can use those to set variables as well (in the appropriate contexts):

JASS:
local unit u = GetTriggerUnit()
local unit u2 = GetKillingUnit()
local unit u3 = GetAttacker()
// etc, etc

But you don't need functions to set variables:

JASS:
local integer i = 50

I just set an integer variable equal to 50 without using any kind of function.

EDIT:

i dont understand what you mean by "hfoo" is a number ... its letters lol?

Search: ASCII in google or wikipedia or something. Basically the short story is that in standard computer systems architecture, every english language character (including all letters, numerals, punctuation) as well as some other common characters is assigned a numeric value. In almost all programming languages, wrapping a character with ' ' (single quotes) converts the character into its assigned numeric value. Which is why 'hfoo' becomes a number.
 
Level 4
Joined
Apr 16, 2009
Messages
85
btw hfoo is not an integer ('hfoo' is one) - thats just another representation of integers

basically there are 3 ways to represent an integer

1. (the normal way) (base 10)

integer a = 16706

2. hexadecimal (hex) (base 16)

integer a = 0x4142
or
integer a = $4142
(<=> 4*16^3+1*16^2+4*16^1+2*16^0 = 1337)

(bold part is the prefix that indicates its a integer in hexadecimal representation)

3. Ascii

integer a = 'AB'
(<=> 0x4142)
(<=> 16706)
(the single quotes indicate its a integer in Ascii representation)

(just use the hexadecimal representation of each letter (http://en.wikipedia.org/wiki/ASCII))
 
uhm... so based on what you said
Number 3:

KillUnit() is just an example function the author is using. It's a native function (one that has already been written by blizzard) that kills a unit. The author is using it to illustrate how to use local variables. You seem to have the wrong idea about variables and functions. Variables and functions are two completely different things. You don't necessarily need one to have the other. However, in most cases functions will use variables to keep track of data and sometimes you need a function to set a variable equal to something:

JASS:
local unit u = CreateUnit(Player(0), 'hfoo', 0, 0, 0)

The function CreateUnit() creates a unit and returns the unit that was created, which is why you can use it to set a unit variable (in this case u) equal to something. There are other functions that return a unit, and you can use those to set variables as well (in the appropriate contexts):

JASS:
local unit u = GetTriggerUnit()
local unit u2 = GetKillingUnit()
local unit u3 = GetAttacker()
// etc, etc

so ... let see how am i gonna ask this ...
the function:
JASS:
function no_name takes nothing returns nothing
 local unit u = GetTriggerUnit() <--- information set #1
 local unit u2 = GetTriggerUnit() <--- information set #2 (which is different from information #1
 local unit u3 = GetTriggerUnit() <--- information set #3 (which is different from 1 and 2)
end function

so basically in this whole function, 3 different unit (maybe at different location facing different places) is uhm... (what does the GetTriggerUnit do anyway? lol) ... manipulated rite? while *u* representing 3 different units

oh and can you (or any1 else) explain:

function no_name takes nothing <---whats this? (the "takes nothing") returns nothing <---whats this?

thx
sorry if im asking too many questions :3
 
2. hexadecimal (hex) (base 16)

integer a = 0x4142
or
integer a = $4142
(<=> 4*16^3+1*16^2+4*16^1+2*16^0 = 1337)

(bold part is the prefix that indicates its a integer in hexadecimal representation)

3. Ascii

integer a = 'AB'
(<=> 0x4142)
(<=> 16706)
(the single quotes indicate its a integer in Ascii representation)

i have no idea what ur talking about ... sorry lol
im not a math genius .. im only taking calc 2 rite now :/
 
Level 4
Joined
Apr 16, 2009
Messages
85
thats very basic math

and

GetTriggerUnit() returns the unit that triggered the event (depends on the event - in addition it will always return the same unit in a given context so what you wrote above u, u2 and u3 would store the same unit)
 
Level 11
Joined
Feb 22, 2006
Messages
752
so basically in this whole function, 3 different unit (maybe at different location facing different places) is uhm... (what does the GetTriggerUnit do anyway? lol) ... manipulated rite? while *u* representing 3 different units

Well, technically, you couldn't use those three specific functions in the same function and have all three work correctly (because of how GetAttacker() and GetKillingUnit() work). But assuming that you could, u, u2, and u3 would all store units. They can be 3 different units, but this doesn't necessarily have to be the case. You can have two variables storing the same unit. You can have any number of variables storing the same unit.

function no_name takes nothing <---whats this? (the "takes nothing") returns nothing <---whats this?

"takes nothing" just means that a function has no parameters. In other words no data needs to be passed to the function when calling it. "returns nothing" means the function has no return type; it doesn't return anything. So for example I can have a function:

JASS:
function Times takes real x, real y returns real
    return x * y
endfunction

This function takes in two reals (floating point numbers) x and y and returns the product of those two numbers. So every time I call the function, I need to pass it two reals and I can expect it to give me back a real:

JASS:
local real r1 = 5.0
local real r2 = 10.0
local real product = Times(r1, r2) // product will now hold the value 50.0

If I have a function that takes nothing returns nothing, it needs no information and it gives me back no information:

JASS:
function SayHello takes nothing returns nothing
    call BJDebugMsg("Hello World!")
endfunction

When I call the function I can call it without giving it any data and I also can't retrieve any data from it. Of course you can also have functions that take in something but return nothing and functions that take in nothing but return something.
 
Status
Not open for further replies.
Top