It's supposed to check for an ore mine on a patch of ore upon which the CRPLcore is also placed. If it finds an ore mine, it shows the image Custom0_128 there at 120 alpha and gets you to click it. Once that's done it builds an ore refinery.
I had this working a while ago, perfectly. Then I must have changed something, and now as soon as the ore miner finishes building (or when state = 2) the game freezes up and the image doesn't appear. I can't work out why this is. I've pasted the entire script below.
script
# thing_build.crpl
# Created on: 11/19/2013 10:01:17 PM
# ------------------------------------------
#state 1 is nonexistent
#state 2 is optioned
#state 21 is optioning
#state 3 is building
#state 4 is unpowered
#state 5 is powered and running
once
Self "main" "NONE" SetImage
1 ->state
Self CONST_TAKEMAPSPACE FALSE SetUnitAttribute
7 SetTextAnchor
0 0 0 255 SetTextColor
-35 SetTextY
0.5 SetTextSize
Self CONST_NULLIFIERDAMAGES FALSE SetUnitAttribute
Self CONST_BUILDCOST 100 SetUnitAttribute
Self CONST_ISBUILDING FALSE SetUnitAttribute
Self CONST_REQUESTPACKETS TRUE SetUnitAttribute
Self CONST_PACKETREQUESTDELAY 2 SetUnitAttribute
Self CONST_CONNECTABLE FALSE SetUnitAttribute
Self CONST_CONNECTABLE TRUE SetUnitAttribute
endonce
<-state 1 eq if
CurrentCoords 0 GetUnitsInRange ->oreUID 0 do
GetUnitType "OREMINE" eq if
2 ->state
endif
loop
endif
<-state 2 eq if
Self "main" "Custom0_128" SetImage
Self "main" 255 255 255 120 SetImageColor
Self "main" 2 2 SetImageScale
21 ->state
endif
<-state 21 eq if
GetMouseCell ->my ->mx
#y 188 - 192
#x 168 - 172
<-my 188 gte <-my 192 lte <-mx 168 gte <-mx 172 lte and and and if
Self "main" 255 255 255 180 SetImageColor
"Click to build Ore Refinery" SetText
0 GetMouseButton if
3 ->state
Self CONST_ISBUILDING TRUE SetUnitAttribute
endif
else
Self "main" 255 255 255 120 SetImageColor
"" SetText
endif
endif
3 <-state eq if
100 Self CONST_BUILDCOST GetUnitAttribute sub SetText
endif
I'm not sure if it's why it's lagging, but the thing I see is that the variable oreUID isn't being used for anything, and is also removing the "in range" unit counter, which you need for the do loop. Instead it's activating a number of times equal to whatever unit UID it reads first, and if it happens to pick the ore mine's UID, the code will fail to recognize that there is one.
I don't expect that to fix the lag issue, but it might. I certainly hope it does. Good luck to you.
Quote from: Clean0nion on November 20, 2013, 08:01:39 PM
It's supposed to check for an ore mine on a patch of ore upon which the CRPLcore is also placed. If it finds an ore mine, it shows the image Custom0_128 there at 120 alpha and gets you to click it. Once that's done it builds an ore refinery.
I had this working a while ago, perfectly. Then I must have changed something, and now as soon as the ore miner finishes building (or when state = 2) the game freezes up and the image doesn't appear. I can't work out why this is. I've pasted the entire script below and attached the map so you can see it in context with images. The attached map will work in both finalized and worldeditor folders.
Sounds like somewhere in the script the code hung up on a command waiting for something that never happened or never will happen, or to put it in layman's terms, crashed.
Good luck in finding it, I know how frustrating bugs can be to find.
Kingo
Quote from: Kingo on November 20, 2013, 11:50:29 PM
Sounds like somewhere in the script the code hung up on a command waiting for something that never happened or never will happen
That could be it. When an ore mine is built, it tries to pull data from an empty stack a large number of times. Either it's stopping because there's no data there, or it's very slow because it keeps trying the same large calculations every frame. Fixing the problem I mentioned actually should solve the lag, unless I'm wrong. It should be as simple as removing the line ->oreUID
By the way, did you mean to make CONNECTABLE turn false and then true in the same frame?
Thanks for your help guys. The ->oreUID is probably the problem, me being lazy and not adding another command. The CONNECTABLE constant - no, that's not supposed to happen. I think I just moved the TRUE from later in the script in an attempt to correct the lag.
UPDATE: Aha! It worked! Thanks very much to both of you.