Basic Equality Always Passing

Started by dklk, April 12, 2021, 04:58:17 PM

Previous topic - Next topic

dklk

Thought i'd try my hand at map making, but i'm having a lot of trouble with even a basic script.

I applied the following to a unit:

$unitGUID:"ccf8aad2-fae0-4f6f-b6b0-6ce86d570f96"
$spawnX:0
$spawnZ:0

@Fire

:Fire
Debug("AMMO")
Debug(GetUnitAmmo(self))
Debug("PosX")
Debug(<-startPos.x)
Debug("PosZ")
Debug(<-startPos.z)

if(GetUnitAmmo(self) eq 10)
RandInt(-20 20) ->rndX
<-startPos.x <-rndX add ->spawnX
Debug("SPAWNX")
Debug(<-spawnX)

RandInt(-20 20) ->rndZ
<-startPos.z <-rndZ add ->spawnZ
Debug("SPAWNZ")
Debug(<-spawnZ)

CreateUnitOnTerrain(<-unitGUID, <-spawnX, <-spawnZ) ->newunit
SetUnitAmmo(self 0)
Debug("TEST1")
endif

#find the units location
:Once
GetUnitPosition(self) ->startPos


I'm having two difficulties I cannot seem to get past though.
First, the equality check on if(GetUnitAmmo(self) eq 10) always passes - even though the debug log shows the ammo at 0 or 1.
Second, the unit spawning never happens. A debug print in the spawning unit (placed under :Once) confirms this - the log shows the co-ordinates calculating fine though. I've triple checked the  spawned unit GUID

Would appreciate any advice!

Edit: I worked out that the equality should be if(GetUnitAmmo(self) 10 eq) so that it pops the two items before, but I still can't fathom why the unit spawning never happens.

Karsten75

#1
Is the CPACK containing that specific unit imported into the map?

Also the command requires a 4th parameter.

https://knucklecracker.com/wiki/doku.php?id=4rpl:commands:createunitonterrain

CreateUnitOnTerrain(<-CmodUID <-cellX <-cellZ <-initParams) ->unitUID


dklk

Thank you! It was the fourth parameter - I was getting confused between the three in createunit and four in createunitonterrain! - Sometimes you can't see the wood for the trees.