Basic Equality Always Passing

dklk · 411

dklk

  • Jr. Member
  • **
    • Posts: 11
on: April 12, 2021, 04:58:17 pm
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:

Code: [Select]
$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.
« Last Edit: April 12, 2021, 05:53:52 pm by dklk »



Karsten75

  • Hero Member
  • *****
    • Posts: 7121
Reply #1 on: April 12, 2021, 06:15:57 pm
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

« Last Edit: April 12, 2021, 06:18:04 pm by Karsten75 »

'If you want to live a happy life, tie it to a goal, not to people or things.'

Albert Einstein
(1879-1955)


dklk

  • Jr. Member
  • **
    • Posts: 11
Reply #2 on: April 13, 2021, 01:47:16 am
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.