| 06-29-2005, 08:14 AM | #1 |
Ok, so I am writing my triggers in JASS now and apart from forgetting "call" occasionaly, things are going along rather nicely. Well, until today, that is. So, I have this piece of code, which worked when I last tried it yesterday, but today, without changing anything of any relevance, it ceased to function. Here's how it looks like: Code:
...
local location loc = GetUnitLoc( u )
set cannon = CreateUnitAtLoc( GetOwningPlayer( u ), GetStoredInteger( udg_gameCache, "cannontype", I2S( GetUnitTypeId( u ) )), loc, GetUnitFacing( u ) )
...I got so frustrated that I added a GUI "create unit" action to one of my triggers, just to see if it will work, after all, when converted to JASS, the function should look very much like what I wrote in JASS anyway. Code:
System Init
Events
Map initialization
Conditions
Actions
Game - Set the time of day to 12.00
Game - Set time of day speed to 0.00% of the default speed
Custom script: call SystemsInit() [i]<--- This function eventually calls the non-working functions written above[/i]
Unit - Create 1 Human Frigate Cannon for (Owner of Human Frigate 0008 <gen>) at (Center of (Playable map area)) facing (Facing of Human Frigate 0008 <gen>) degreesI have a secondary problem as well. This cannon unit I create is supposed to be the main gun of a ship which fires whenever the ship casts a special spell. I originaly created it just before fireing, but the results were a bit erratic, sometimes the cannon would recieve the damage bonus from the ships aura and sometimes it managed to fire before the aura buff was applied. So, I decided to create the cannon unit when the player buys the ship and move it along like I do the ship turrets, so that when it were required to fire, it would already be under effects of any auras. However, the cannon then acted like a turret, acquireing enemy targets on it's own, despite the fact that it's attack "targets allowed" were set to only "terrain". I tried hiding the turret and unhiding it only on those occasions when the ship casts the "fire main cannon" spell, but unhiding had the same effect as creating the unit, it sometimes recieved damage bonuses in time and sometimes it just fired too quickly. I tried setting the "targets allowed" to "terrain" and "none", which ceased the auto-target-acquisition, but setting it to "none" made the attack information in the unit's status bar dissapear. The unit could still attack ground as intended, but the attack didn't get any aura bonuses at all. Last thing I tried seemed obvious that it should work: Code:
call SetUnitAcquireRangeBJ( cannon, 0 ) |
| 06-29-2005, 03:38 PM | #2 |
Is this 'u' unit variable initialized? |
| 06-29-2005, 04:27 PM | #3 | |
Quote:
Anyway, here are all the relevant functions and triggers: Code:
// ***************************
// **** GENERAL FUNCTIONS ****
// ***************************
function H2I takes widget H returns integer
return H
return 0
endfunction
function I2U takes integer I returns unit
return I
return null
endfunction
function H2S takes widget H returns string
return I2S( H2I( H ) )
endfunction
// ****************************
// **** MAIN WEAPON SYSTEM ****
// ****************************
function CreateMainGun takes unit u returns nothing
local unit cannon
local location loc = GetUnitLoc( u )
[b]//the following line doesn't appear to work unless... (check the init trigger)
set cannon = CreateUnitAtLoc( GetOwningPlayer( u ), GetStoredInteger( udg_gameCache, "cannontype", I2S( GetUnitTypeId( u ) )), loc, GetUnitFacing( u ) )[/b]
call StoreInteger( udg_gameCache, "cannonunit", H2S( u ), H2I( cannon ) )
//the following line doesn't prevent the unit from auto acquireing targets (but neither does a GUI action)
call SetUnitAcquireRangeBJ( cannon, 0 )
//debug message
call DisplayTimedTextToPlayer( Player(0), 0, 0, 5, GetUnitName( cannon ))
set cannon = null
call RemoveLocation( loc )
set loc = null
endfunction
function CannonSystemInit takes nothing returns nothing
call StoreInteger( udg_gameCache, "cannontype", I2S( 'H00C' ), 'h01T' )
//the following line is supposed to create a main cannon for a preplaced test unit
call CreateMainGun( gg_unit_H00C_0008 )
endfunction
function SystemsInit takes nothing returns nothing
set udg_gameCache = InitGameCache( "test" )
call CannonSystemInit()
call TurretSystemInit()
endfunctionCode:
System Init
Events
Map initialization
Conditions
Actions
Game - Set the time of day to 12.00
Game - Set time of day speed to 0.00% of the default speed
Custom script: call SystemsInit()
[b]//adding the following line makes the nonworking function suddenly work :/
Unit - Create 1 Human Frigate Cannon for (Owner of Human Frigate 0008 <gen>) at (Center of (Playable map area)) facing (Facing of Human Frigate 0008 <gen>) degrees[/b]
//I tried if setting acquisition range would work as well if I tried it in GUI, but it doesn't, the ships turret as well as the turret created with the previous action both auto-acquire targets
Unit - Set (Last created unit) acquisition range to 0.00 |
| 06-29-2005, 04:40 PM | #4 |
sometimes the variables like gg_unit_H00C_0008 start pointing to null for no reason, try using call BJDebugMsg(GetUnitName(gg_unit_H00C_0008)) some where to see if it points out to the right unit |
| 06-29-2005, 05:04 PM | #5 |
Indeed, that was the case. If I were to draw a conclusion just from this case, I'd say variables for preplaced units don't work unless there's a GUI action using them... Anyway, I'll spawn my test unit with a trigger instead of preplacing it and I'll be rid of this bug. Thanks Vex. |
| 06-30-2005, 11:36 AM | #6 |
dont you need to call create unit, and the set the variable to canon? i know you can sometimes set a variable like that, but it might be worth checking |
| 07-01-2005, 03:50 PM | #7 |
Unexplainable problems continiue... Code:
set cannon = CreateUnitAtLoc( GetOwningPlayer( u ), GetStoredInteger( udg_gameCache, "projectiletyp", I2S( GetUnitTypeId( u ) )), loc2, GetUnitFacing( u ) )
call GroupAddUnitSimple( cannon, udg_particleGroup )
call BJDebugMsg( GetUnitName( cannon ) )
call BJDebugMsg( I2S(CountUnitsInGroup( udg_particleGroup )) )And there's more. I tried defining the group at start so it includes two preplaced units, to see if this will make the previous function work, but it only shows more things not working. I have the following function being called by a periodic trigger: Code:
function MoveAllParticles takes nothing returns nothing
local unit u
local group ug
set ug = udg_particleGroup
call BJDebugMsg( I2S(CountUnitsInGroup( udg_particleGroup )) ) //DEBUG NUMBER 1
loop
exitwhen ( CountUnitsInGroup( ug ) == 0 )
set u = FirstOfGroup( ug )
call GroupRemoveUnit( ug, u )
call MoveParticle( u )
endloop
call BJDebugMsg( I2S(CountUnitsInGroup( udg_particleGroup )) ) //DEBUG NUMBER 2
call DestroyGroup( ug )
call BJDebugMsg( I2S(CountUnitsInGroup( udg_particleGroup )) ) //DEBUG NUMBER 3
set ug = null
set u = null
endfunction |
| 07-01-2005, 04:34 PM | #8 |
You are missunderstanding Everything! =) The best way to understand Variables of types that are derived from handle is to get them the same way as units. For example Code:
function Err takes unit u returns nothing local unit A=u // It obviously won't create a new unit that is just like u endfunction So when you set that local group to the value of that global group, both variables are pointing the same group, if you call destroyGroup with either of the variables it will destroy the group that is pointed by the variables. |
| 07-01-2005, 05:15 PM | #9 |
:( I knew all that, how did I miss it... Well, now it all works flawlessly... well, except that cannonballs fly twice as far as they should... |
