Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: Clean0nion on November 20, 2013, 02:47:55 PM

Title: Can anyone see why this script does nothing?
Post by: Clean0nion on November 20, 2013, 02:47:55 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.

# 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
Title: Re: Can anyone see why this script does nothing?
Post by: eduran on November 20, 2013, 04:04:32 PM
GetUnitAt returns only one unit. I don't know how it selects one if there are several on the same cell. If it's not the ore mine your script does not work. Try to replace the GetUnitAt with GetUnitsInRange:

<-state 1 eq if
CurrentCoords 0 GetUnitsInRange 0 do
GetUnitType "OREMINE" eq if
     @BuildOption
     2 ->state 
endif
loop
endif
Title: Re: Can anyone see why this script does nothing?
Post by: Clean0nion on November 20, 2013, 04:22:09 PM
Quote from: eduran on November 20, 2013, 04:04:32 PM
GetUnitAt returns only one unit. I don't know how it selects one if there are several on the same cell. If it's not the ore mine your script does not work. Try to replace the GetUnitAt with GetUnitsInRange;
eduranic praise
Wow, that works! Thanks Eduran!
[close]
Title: Re: Can anyone see why this script does lowers game to 1 or 2 frames per second?
Post by: Clean0nion on November 20, 2013, 07:00:12 PM
Massive lag problem posted. Can anyone help me with this? (see OP for details)
Title: Re: Can anyone see why this script does lowers game to 1 or 2 frames per second?
Post by: Grauniad on November 20, 2013, 07:19:49 PM
Stop. Repurposing. Threads. By . Changing. Subjects. I'm. Sure. It. Confuses. More. People. Than. Just. Me. You have.  My. Blessing. On. Being. A. Multiple. Thread. Starter.
Title: Re: Can anyone see why this script does lowers game to 1 or 2 frames per second?
Post by: Clean0nion on November 20, 2013, 07:59:37 PM
Thank you Granuiad. Thread locked.