Help with new unit

Started by driesemol, August 21, 2015, 11:45:44 AM

Previous topic - Next topic

driesemol

I'm trying to make a new unit (note that i'm not that familiar with CRPL yet) and it doesn't want to work.
The 'not working when in creeper' part should work fine
The problem lies in its action: when ammo is full, it should go to orbit, make it rain AC and then return from orbit.
The tricky part lies in returning from orbit. Although the wiki says you can return after ascending, further search on this forum informed me that the unit is destroyed after ascending. Thus I tried making a new unit after destruction, invisible until it descends.
What happens exactly is quite strange. I suggest that you try it and see for yourself. I hope someone can help me with this :)


# ProjectKC4Unit.crpl
# author: driesemol
# start: 20/8/2015

# A friendly connectable unit that ascends to orbit when ammo full
# makes it rain AC and then returns from orbit
# can't charge/connect when in creeper

# Set base specs for friendly connectable unit


once
$MaxAmmo:1000.0
Self CONST_COUNTSFORVICTORY False SetUnitAttribute
Self CONST_NULLIFIERDAMAGES False SetUnitAttribute
Self CONST_CREATEPZ False SetUnitAttribute
90 Delay

Self CONST_MAXAMMO <-MaxAmmo SetUnitAttribute
Self CONST_PACKETREQUESTDELAY 10 SetUnitAttribute
Self CONST_SHOWAMMOBAR True SetUnitAttribute
Self CONST_AMMO 0 SetUnitAttribute
endonce

Self CONST_AMMO GetUnitAttribute ->Ammo


#check if no creeper is present at current coords
#no creeper: connectable

CurrentCoords GetCreeper 0 lte  if
Self CONST_CONNECTABLE True SetUnitAttribute
Self CONST_CANREQUESTAMMO True SetUnitAttribute
Self CONST_REQUESTPACKETS True SetUnitAttribute
else
Self CONST_CONNECTABLE False SetUnitAttribute
Self CONST_CANREQUESTAMMO False SetUnitAttribute
Self CONST_REQUESTPACKETS False SetUnitAttribute
endif

#when ammo is full, create 50 AC raindrops
#decend from orbit (new unit, DropFromOrbit doesn't work after ascendtoorbit)

<-MaxAmmo <-Ammo eq if
AscendToOrbit

90 Delay
50 -50 MakeRain
Self 0 Destroy
endif

:destroyed
"CRPLCORE" CurrentCoords CreateUnit ->newCore
<-newCore "projectKC4.crpl" AddScriptToUnit
<-newCore "projectKC4.crpl" "MaxAmmo" <-MaxAmmo SetScriptVar
<-newCore "main" "None" SetImage
<-newCore 300 Delay
<-newCore "main" "CRPLCORE" SetImage
<-newCore CurrentCoords DropFromOrbit



warren

Yes, that is one of the many things that can happen if you attempt to use a destroyed object. That can also happen if you do one of many other things that should be impossible. as far as I can tell, :destroyed is never called after AscendToOrbit, but it is effectively dead.

driesemol

Quote from VirgilW at another post:

QuoteI'm not so sure about the "drop from orbit will recover" part.  From my recollection ascend to orbit destroys the unit at the end of the cycle.  "Orbit" is purely an imaginary place and I don't recall keeping units around in any state or data structures when they ascend.  A quick look at the code shows that at the end of the ascension sequence, "Destroy" is called on the unit...

it seems the destroy function IS called at the end of AscendToOrbit. I'll try again to see if i can fix it though :)