HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

It is a Real Number!

12-01-2004, 06:15 PM#1
Sicknesslife
Hi,

I am creating a really simple trigger to help me understand JASS a bit better but the editor is giving me a stupid error:

Code:
function Trig_CreepsImproved_Actions takes nothing returns nothing
    local location TempPoint = GetUnitLoc(gg_unit_hgtw_0006)
    local real Test = 180.00
    CreateUnitAtLocByName(Player(0),'ogru',TempPoint,Test)
endfunction

//===========================================================================
function InitTrig_CreepsImproved takes nothing returns nothing
    set gg_trg_CreepsImproved = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_CreepsImproved, 4.00 )
    call TriggerAddAction( gg_trg_CreepsImproved, function Trig_CreepsImproved_Actions )
endfunction


it tells me: Invalid argument type(integer)
for this line:


CreateUnitAtLocByName(Player(0),'ogru',TempPoint,Test)


anyhelp??


please ignore the space in test, t est tht is not in my code it is just a forum error
12-01-2004, 06:25 PM#2
Ryude
Don't set the TempPoint in local definition.

do this:

local location loc
set loc = GetUnitLoc(gg_unit_hgtw_0006)

At least that's what I would guess without actually opening the editor.
However, I believe you can set reals and integers in the definition.

You can always try setting the real like that too:

local real test
set test = 180.00
12-01-2004, 06:45 PM#3
Sicknesslife
Quote:
Originally Posted by Ryude
Don't set the TempPoint in local definition.

do this:

local location loc
set loc = GetUnitLoc(gg_unit_hgtw_0006)

At least that's what I would guess without actually opening the editor.
However, I believe you can set reals and integers in the definition.

You can always try setting the real like that too:

local real test
set test = 180.00


When I try it that way I t gives me errors saying:Expected Variable name

Code:
function Trig_CreepsImproved_Actions takes nothing returns nothing
    local location TempPoint 
    set TempPoint = GetUnitLoc(gg_unit_hgtw_0006)
    local real Test
    set Test = 20.25
    CreateUnitAtLocByName(Player(0),'ogru',TempPoint,Test)
endfunction

//===========================================================================
function InitTrig_CreepsImproved takes nothing returns nothing
    set gg_trg_CreepsImproved = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_CreepsImproved, 4.00 )
    call TriggerAddAction( gg_trg_CreepsImproved, function Trig_CreepsImproved_Actions )
endfunction

it gives me that on:

set Test = 20.25
12-01-2004, 06:55 PM#4
Kolibri
Quote:
Originally Posted by Sicknesslife
Hi,

I am creating a really simple trigger to help me understand JASS a bit better but the editor is giving me a stupid error:

Code:
function Trig_CreepsImproved_Actions takes nothing returns nothing
    local location TempPoint = GetUnitLoc(gg_unit_hgtw_0006)
    local real Test = 180.00
    CreateUnitAtLocByName(Player(0),'ogru',TempPoint,Test)
endfunction

//===========================================================================
function InitTrig_CreepsImproved takes nothing returns nothing
    set gg_trg_CreepsImproved = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_CreepsImproved, 4.00 )
    call TriggerAddAction( gg_trg_CreepsImproved, function Trig_CreepsImproved_Actions )
endfunction


it tells me: Invalid argument type(integer)
for this line:


CreateUnitAtLocByName(Player(0),'ogru',TempPoint,Test)


anyhelp??


please ignore the space in test, t est tht is not in my code it is just a forum error


Don't forget the call infront of functions:

call CreateUnitAtLocByName(Player(0),'ogru',TempPoint,Test)

You use call when it's just a function, eg.

call KillUnit(udg_blabla)
call DisplayTextToForce( GetPlayersAll(), "hmm" )

but not when it is part of a line

local location bla = GetUnitLoc(udg_blabla)
set bla = GetUnitLoc(Udg_blabla)
12-01-2004, 07:06 PM#5
Ryude
Ya, that should work what Kolibri said.
12-01-2004, 07:26 PM#6
Sicknesslife
I changed the code the way you recommended, but i am getting a different error now

Code:
function Trig_CreepsImproved_Actions takes nothing returns nothing
    local location TempPoint 
    set TempPoint= GetUnitLoc(gg_unit_hgtw_0006)
    local real T 
    set T = 3.33
    call CreateUnitAtLocByName(Player(0),'ogru',TempPoint,T)
endfunction

//===========================================================================
function InitTrig_CreepsImproved takes nothing returns nothing
    set gg_trg_CreepsImproved = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_CreepsImproved, 4.00 )
    call TriggerAddAction( gg_trg_CreepsImproved, function Trig_CreepsImproved_Actions )
endfunction


Now i get: Expected a code statement

Code:
local real T 

it doesnt seem to be initializing T, I am having problems with reals
12-01-2004, 07:27 PM#7
Ryude
Define all your local variables before setting any of them.
Example:

local location TempPoint
local real T
set TempPoint = blah
set real T = 3.33
12-01-2004, 08:09 PM#8
Kolibri
Quote:
Originally Posted by Ryude
Define all your local variables before setting any of them.
Example:

local location TempPoint
local real T
set TempPoint = blah
set real T = 3.33

Yeah.

Also there is nothing wrong with setting the variable when you declare it. Eg. this is fine

Code:
function Trig_CreepsImproved_Actions takes nothing returns nothing
    local location TempPoint = GetUnitLoc(gg_unit_hgtw_0006)
    local real Test = 180.00
    [b]call[/b] CreateUnitAtLocByName(Player(0),'ogru',TempPoint,T  est)
endfunction

Unlike what you were told earlier.
12-01-2004, 08:18 PM#9
Sicknesslife
Code:
function Trig_CreepsImproved_Actions takes nothing returns nothing
    local location TempPoint = GetUnitLoc(gg_unit_hgtw_0006)
    local real T = 3.33 
    call CreateUnitAtLocByName(Player(0),'ogru',TempPoint,T)
endfunction


This is the newest incarnation/manifestation of my SIMPLE trigger it gives me the exact same errors

invalid argument type(integer)
12-01-2004, 09:50 PM#10
a thing
1. Since you said you're learning JASS, here's a few tips:

-You do NOT need spaces before and after operators (>, <, <=, >=, ==, and !=) or the characters "(" and ")".

-You ONLY need "(" and ")" when they surround parameters you're passing to a function.

2. Try removing the space at the end of the line. If that doesn't work, set T to a number with out a decimal (no, you don't get a syntax error for that) or just use R2I (real to integer) to convert T into an integer.
12-01-2004, 09:55 PM#11
Ryude
Weird, then why does my code not work if I set it in the variable?

Thx for the tip.
12-01-2004, 09:57 PM#12
Kolibri
I found the error. :)

Code:
function Trig_CreepsImproved_Actions takes nothing returns nothing
    local location TempPoint = GetUnitLoc(gg_unit_hgtw_0006)
    local real T = 3.33 
    call CreateUnitAtLocByName(Player(0),'ogru',TempPoint,T  )
endfunction

should be

Code:
function Trig_CreepsImproved_Actions takes nothing returns nothing
    local location TempPoint = GetUnitLoc(gg_unit_hgtw_0006)
    local real T = 3.33 
    call CreateUnitAtLoc(Player(0),'ogru',TempPoint,T  )
endfunction

CreateUnitAtLocByName takes the unit's name, not it's ID (eg. 'ogru'). So use CreateUnitAtLoc instead.

Finally, a small lesson in memory leaks. Creating a location leaks (eg. GetUnitLoc(), PolarProjectionBJ(), GetRectCenter(), etc.). So you need to remove the location when you are DONE with it. After removing the location you need to set the location variable to null (because that leaks too).

So the function should be

Code:
function Trig_CreepsImproved_Actions takes nothing returns nothing
    local location TempPoint = GetUnitLoc(gg_unit_hgtw_0006)
    local real T = 3.33 
    call CreateUnitAtLoc(Player(0),'ogru',TempPoint,T  )
    call RemoveLocation( TempPoint )
    set TempPoint = null
endfunction

call RemoveLocation( TempPoint ) removes the TempPoint location.
set TempPoint = null sets the variable to null, so that it won't leak.

Notice that not only creating locations leaks memory if not destroyed. Sounds, Groups and others leak too. I recommend doing a search here on wc3c for memory leaks.
12-01-2004, 10:04 PM#13
Ryude
I think you explained it quite well, gj.

Also, if you haven't seen it, go to http://www.sw0bes.com/mlindicator/.
12-02-2004, 04:50 AM#14
Sicknesslife
Thank you all very much for all your help, my problem came from misunderstanding what a unit name vs id where, i thought 'ogru' was the name becuase it was a string.... apparently i was wrong. I knew about removing the locations and nulling the var but thanks so much anyway.


P.S. Ryude your link is broken....
12-02-2004, 11:53 AM#15
Ryude
No it's not...server may have been down when you checked.