ID:149602
 
I`m trying to get my REMBLOCK() proc to remove all /obj/Blocks that have their "typ" var set to "12"

this is the code i am using, and I get some CT errors:

The Proc:
REMBLOCK()
for(var/obj/O in world)
if(istype(O,/obj/Block))
if(O.typ== "12")
del(O)

The obj:
obj
Block
icon = 'Blocks.dmi'
icon_state = "Block"
var/typ
the CT Errors:

loading Blockheads.dme
Code.dm:85:error:O.typ:undefined var
Code.dm:85:if :warning: if statement has no effect

Blockheads.dmb - 1 error, 1 warning (double-click on an error to jump to it)


as usual my attempts at coding anything good are completely destroyed. Any help will be apreciated
Form a cast. Create an obj/Block var and access the Block members of that.

    REMBLOCK()
for(var/obj/O in world)
if(istype(O,/obj/Block))
var/obj/Block/b = O
if(b.typ== "12")
del(O)


PS: I've answered the same question in [link] and [link] today. Kooky.
In response to ACWraith
ACWraith wrote:
Form a cast. Create an obj/Block var and access the Block members of that.

>   REMBLOCK()
> for(var/obj/O in world)
> if(istype(O,/obj/Block))
> var/obj/Block/b = O
> if(b.typ== "12")
> del(O)
>

PS: I've answered the same question in [link] and [link] today. Kooky.

aww crap, I knew that post looked important! Sorry!
In response to Pillsverry
Pillsverry wrote:
aww crap, I knew that post looked important! Sorry!

It wasn't a slam. I was just tracing my day and wondering how many people have problems with casts. (Besides, I'd like to get the general "cast" term into the open so people understand all of the specific "use this var instead of that var to access this member" cases. ;) )
In response to ACWraith
ACWraith wrote:
Form a cast. Create an obj/Block var and access the Block members of that.

>   REMBLOCK()
> for(var/obj/O in world)
> if(istype(O,/obj/Block))
> var/obj/Block/b = O
> if(b.typ== "12")
> del(O)
>


This is completely unnecessary. If the type had been specified in the first place, not only would you not need to check for it with your first if statement, but you would not need a cast.

  REMBLOCK()
for(var/obj/Block/B in world)
if(B.typ== "12")
del(B)