Depleating and refilling

Started by Edward, January 06, 2016, 02:29:30 PM

Previous topic - Next topic

Edward

Hello.
Pretty new to this "reverse" language. I'm very used to the "forward C". ;)
But I've looked up a lot of things, used the wiki as best as I can, and Googled other things. The little I've done and edited from other people have turned out nicely. But there are still things that I can't quite do (in reverse).

I am now attempting to create some kind of creeper bomb. The bomb works like this:
It is filled with either AC or C using the standard values of -2000 to 2000. When "eaten" by creeper, it will explode and unload its load. However, I allow the player to connect to it and fill it with AC. Now, the conversion process isn't immediate. First the AC neutralizes the C load, then it can be filled with AC.

Well, all seems to work. Accepts ACAmmo, Explodes and releases its load, BUT the values don't move, and I can't seem to figure out where the problem lies or how best to change things. Could I have some help here?

# CreeperBomb.crpl
# Created on: 2015/01/06
# Author: Edward
# ------------------------------------------

$cramt:2000

once
SetUnitAttribute(self CONST_CONNECTABLE TRUE)
SetUnitAttribute(self CONST_ACPACKETREQUESTDELAY 1)
SetUnitAttribute(self CONST_REQUESTACPACKETS TRUE)
SetUnitAttribute(self CONST_REQUESTPACKETS FALSE)
SetUnitAttribute(self CONST_CANREQUESTAMMO FALSE)

SetUnitAttribute(self CONST_DESTROYONDAMAGE TRUE)
SetUnitAttribute(self CONST_CREATEPZ TRUE)
SetUnitAttribute(self CONST_COUNTSFORVICTORY FALSE)

SetUnitAttribute(self CONST_MAXHEALTH 10)
SetUnitAttribute(self CONST_HEALTH 10)
SetUnitAttribute(self CONST_MAXAMMOAC 2000)
SetUnitAttribute(self CONST_MAXAMMO 2000)

SetUnitAttribute(self CONST_SHOWAMMOACBAR TRUE)
SetUnitAttribute(self CONST_SHOWAMMOBAR TRUE)
SetUnitAttribute(self CONST_SHOWHEALTHBAR TRUE)
endonce

SetPopupText (GetUnitAttribute(self CONST_AMMOAC))
(GetUnitAttribute(self CONST_AMMOAC) 0 gt)
(GetUnitAttribute(self CONST_AMMO) 0 gt)
if(and)
<-cramt 1 sub ->cramt
else
(GetUnitAttribute(self CONST_AMMOAC) 0 gt)
(GetUnitAttribute(self CONST_AMMO) 0 eq)
if(and)
<-cramt GetUnitAttribute(self CONST_AMMOAC) neg
endif
endif

#SetPopupText (<-cramt)

if(<-cramt 0 lt)
SetImage(self "main" "Custom7")
SetUnitAttribute(self CONST_AMMO 0)
SetUnitAttribute(self CONST_AMMOAC <-cramt neg)
else
SetImage(self "main" "Custom6")
SetUnitAttribute(self CONST_AMMO <-cramt)
SetUnitAttribute(self CONST_AMMOAC 0)
endif

if(CurrentCoords GetCreeper 0 gt)
Damage(self GetCreeper(CurrentCoords))
endif

:destroyed
SetCreeper(CurrentCoords <-cramt)



PS. Funny thing: When trying to set "Request AC Packets" in the editor, it gets unset after Load. :s

J

Looks like this part isn't what you intended it to be

SetPopupText (GetUnitAttribute(self CONST_AMMOAC))
(GetUnitAttribute(self CONST_AMMOAC) 0 gt)
(GetUnitAttribute(self CONST_AMMO) 0 gt)
if(and)

Unwrapping the code gives this:

self CONST_AMMOAC GetUnitAttribute
self CONST_AMMOAC GetUnitAttribute 0 gt
self CONST_AMMO GetUnitAttribute 0 gt SetPopupText
and if

I guess you didn't want SetPopupText to end up there, so try it again with this:

SetPopupText (GetUnitAttribute(self CONST_AMMOAC))
if(GetUnitAttribute(self CONST_AMMOAC) 0 gt
GetUnitAttribute(self CONST_AMMO) 0 gt and)


Same for the if condition after the else statement a bit later
(GetUnitAttribute(self CONST_AMMOAC) 0 gt)
(GetUnitAttribute(self CONST_AMMO) 0 eq)
if(and)

Should be
GetUnitAttribute(self CONST_AMMOAC) 0 gt
GetUnitAttribute(self CONST_AMMO) 0 eq
and if

(sorry for using slightly different coding styles, I personally prefer the latter while most other don't)

GameGibu

If you look under GetUnitAttribute on the wiki, it says that it uniquely does not persist between saves. A way around this, if it should always be able to request AC packets, add
:awake
    Self CONST_REQUESTACPACKETS 1 SetUnitAttribute

to your code. awake is called when the game loads, so this should effectively eliminate that problem area.

Hope this helps! ;D
-GameGibu
Bringing you Custom maps since 2971!
☆CRPL Master☆

Builder17

:GameLoaded works better than awake actually. Awake doesn't work every game load , I think.
Is there any other problem anymore?

GameGibu

Look here. There's probably an advantage here to use both just to make double sure that that constant is set every game load.

-GameGibu
Bringing you Custom maps since 2971!
☆CRPL Master☆

Edward

Ok. Thanks. Reworked those 2 ifs and added the :GameLoaded. Also, noticed that I had the cramt on the wrong end when it was time to add the AC. Now it all works like a charm.