ID:147206
 
Ok can someone out there PLEASE tell me what is wrong with this program I wrote? It is supposed to make a shield icon in every direction around the mob and then follow him around. What it is doing is making a single shield in front of the mob, making black spaces everywere else where other shileds should be, and it wont move with him. Heres the code.turf/shield1
icon = 'sspell.dmi'
icon_state = "1"
density = 1
turf/shield2
icon = 'sspell.dmi'
icon_state = "2"
density = 1
turf/shielde
icon = 'sspell.dmi'
icon_state = "3"
density = 1
turf/shieldw
icon = 'sspell.dmi'
icon_state = "4"
density = 1

mob/verb/shield()
new/turf/shield1(locate(x,y+1,z))
new/turf/shield2(locate(x,y-1,z))
new/turf/shielde(locate(x+1,y,z))
new/turf/shieldw(locate(x-1,y,z))
spawn(20)
for(var/turf/shield1/S in view())
del S
for(var/turf/shield2/W in view())
del W
for(var/turf/shielde/E in view())
del E
for(var/turf/shieldw/W in view())
del W

Can someone please fix this? I cant think of anything else I
could try and right now I've basicly given up hope. So someone please help?
Ok. You've sort of dug yourself into a pretty big hole here.
First, the shields shouldn't be turfs. I recommend using objs, although a mob could do the job it's not really right for the job.

You've got a spawn(20) in there. I'm not sure what you've tried to do there. You've either tried to use spawn() instead of sleep(), or you've forgotten to indent the stuff after spawn(). Ie.
spawn(20)
//The stuff that gets done 20 ticks later.
//The rest of the proc/verb.

A sleep() would work exactly as you have it except with spawn(20) replaced with sleep(20).

You're also failing to properly track the shields. Instead of scrolling through the stuff in oview(), wouldn't it be easier to just have variables pointing to the specific objects you created?

Now this isn't going to follow the player around. It'll actually stop the player from moving (because they'll bump into the dense objs surrounding them).
I'll try and quickly write you up a demo explaining some techniques that you'd use. I'll reply with it as soon as possible.

Also, when on the forums you should make use of the <dm> HTML tag when showing code (as I did above). If you don't know HTML just put a <dm> tag at the start of the code snippet, then a </dm> tag at the end of the snippet.
The tags are only used on BYOND Forums but it makes it much easier for the people who help out here to help you.
In response to DarkView
Ok. This may be a little hard to get your head around, so feel free to ask any questions.

/*

Ok. In short what we're doing here is creating a bunch of variables to hold the shield objects.
Then we're making two procs. These procs activate and deactivate the shields.
We've also got a debug verb that calls either of those procs depending on if the shields are up or not.
Then we modify the Move() proc (the proc that moves the mobs/objs around the map) to move the shields with the mob (only if their shields are up).




*/


//Create the prototypes for the shield objects.
obj
shieldS
density = 1
shieldN
density = 1
shieldE
density = 1
shieldW
density = 1



mob
var
obj/shieldS/southS //Create a var named southS to store an object of the type /obj/shieldS
obj/shieldN/northS //Same as before, but with the name northS and the type /obj/shieldN
obj/shieldE/eastS //Same as before, but with the name eastS and the type /obj/shieldE
obj/shieldW/westS //Same as before, but with the name westS and the type /obj/shieldW
shieldsUp
proc
addShield()
//Assign a bunch of new objects to the shield variables.
src.southS = new /obj/shieldS
src.northS = new /obj/shieldN
src.eastS = new /obj/shieldE
src.westS = new /obj/shieldW
//Set the shieldsUp variable to 1 (aka, TRUE).
src.shieldsUp = 1
removeShield()
//Delete all the shield objects.
del(src.southS)
del(src.northS)
del(src.eastS)
del(src.westS)
//Set the shieldsUp variable to 0 (aka, FALSE).
src.shieldsUp = 0
verb
shieldToggle()
if(src.shieldsUp) //Check to see if src.shieldsUp is not null (aka, TRUE, or any value other then "", 0 or null)
src << "Flame off."
//Call the players "removeShield()" proc.
src.removeShield()
else
src << "Flame on!"
//Call the players "addShield()" proc
src.addShield()
//Here we're over-riding the built in proc "Move()" that objs and mobs have.
//You can tell that we're over-riding a proc/verb because we don't put the "proc" part before it.
//That tells the compiler that we're over-riding something that mobs already have, and from there it can figure out if it's a verb or proc on it's own.
Move()
. = ..() //Do the normal stuff. This is very important.
if(src.shieldsUp) //Check to see if src.shieldsUp is not null (aka, TRUE, or any value other then "", 0 or null)
src.southS.loc = get_step(src,SOUTH) //Move the object in shieldS to get_step(src,SOUTH). aka a step south of the player.
src.northS.loc = get_step(src,NORTH)
src.eastS.loc = get_step(src,EAST)
src.westS.loc = get_step(src,WEST)
In response to DarkView
Thanks man. I've completely got it figured out now. Also thanks for the tip about the html tag thing. In short: Thanks