ID:266343
 
While debugging some code I gave to a newbie, I ran into a code error that I cannot fix: invalid expression. I've gotten those before, but not in case like this. I'll show you the proc and highlight the lines with the invalid expression errors:

mob/verb/shootlaser()
set name = "Shoot Laser"
var/obj/laserfront = new /obj/laser/front (null)
var/obj/laserback = new /obj/laser/back (null)
laserfront.dir = src.dir
laserback.dir = src.dir// from here to
switch(src.dir)
if(NORTH)
laserback.loc = locate(src.x,src.y+1,src.z)
laserfront.loc = locate(src.x,src.y+2,src.z)
if(SOUTH)
laserback.loc = locate(src.x,src.y-1,src.z)
laserfront.loc = locate(src.x,src.y-2,src.z)
if(EAST)
laserfront.loc = locate(src.x+2,src.y,src.z)
laserback.loc = locate(src.x+1,src.y,src.z)
if(WEST)
laserback.loc = locate(src.x-1,src.y,src.z)
laserfront.loc = locate(src.x-2,src.y,src.z)
else
src << "You must be facing a cardinal direction to fire a laser."
return
var/traveldistance = rand(5,9) + laser_skill// What is i? [i is just a number deciding how far the laser will travel. I'll rename it traveldistance.]
while(traveldistance)
laserfront.Move(laserfront.dir)
laserback.Move(laserback.dir)
traveldistance -= 1
spawn(1)
del(laserfront)
del(laserback)

I hope somebody can help me figure this out. Thanks for your time!

-Lord of Water

[Edit] Lines highlighted now! [/Edit]
Lord of Water wrote:
I'll show you the proc and highlight the lines with the invalid expression errors:

I don't see any highlighted lines...
In response to Deadron
the del(blah) lines?
In response to Tapion1
Yes, those. I have used del() before many times, and have never had invalid expression errors... does anyone know what I am doing wrong?
Im thinking the compiler didnt get the right lines, it does that sometimes. Otherwise, i have no clue.

FIREking

Lord of Water wrote:
While debugging some code I gave to a newbie, I ran into a code error that I cannot fix: invalid expression. I've gotten those before, but not in case like this. I'll show you the proc and highlight the lines with the invalid expression errors:

mob/verb/shootlaser()
set name = "Shoot Laser"
var/obj/laserfront = new /obj/laser/front (null)
var/obj/laserback = new /obj/laser/back (null)
laserfront.dir = src.dir
laserback.dir = src.dir// from here to
switch(src.dir)
if(NORTH)
laserback.loc = locate(src.x,src.y+1,src.z)
laserfront.loc = locate(src.x,src.y+2,src.z)
if(SOUTH)
laserback.loc = locate(src.x,src.y-1,src.z)
laserfront.loc = locate(src.x,src.y-2,src.z)
if(EAST)
laserfront.loc = locate(src.x+2,src.y,src.z)
laserback.loc = locate(src.x+1,src.y,src.z)
if(WEST)
laserback.loc = locate(src.x-1,src.y,src.z)
laserfront.loc = locate(src.x-2,src.y,src.z)
else
src << "You must be facing a cardinal direction to fire a laser."
return
var/traveldistance = rand(5,9) + laser_skill// What is i? [i is just a number deciding how far the laser will travel. I'll rename it traveldistance.]
while(traveldistance)
laserfront.Move(laserfront.dir)
laserback.Move(laserback.dir)
traveldistance -= 1
spawn(1)
<font color='lime'>del(laserfront)</font>
<font color='lime'>del(laserback)</font>

I hope somebody can help me figure this out. Thanks for your time!

-Lord of Water

[Edit] Lines highlighted now! [/Edit]
In response to FIREking
Well, do you see any other line that the invalid expression would have stemmed from? I don't so I tend to beleive the compiler.
In response to FIREking
Try del laserfront and del laserback . del(x) is the old style syntax. del x is preffered now. I thought both of them worked, though. Could be a bug of sorts.

-AbyssDragon
In response to Lord of Water
It may be in the the Move() lines. Move wants a location as the first argument. I'd expect a different error message though. Try

step(laserfront,laserfront.dir)
step(laserback,laserback.dir)

instead.
In response to Shadowdarke
I changed del(laserfront) to del laserfront and the same with laserback, and I replaced move with step(). I am begginning to think there is a compiler bug, because these errors will not go away.
In response to AbyssDragon
AbyssDragon wrote:
Try del laserfront and del laserback . del(x) is the old style syntax. del x is preffered now. I thought both of them worked, though. Could be a bug of sorts.

-AbyssDragon

i always use the parenthesis.

dont know where you got this "this is the prefered way now" thing at. =\

FIREking
spawn(1)

You aren't spawning anything. That's where a sleep() should be.

(Gads, you guys! You're supposed to debug his code for him and you didn't even check the lines above?! =P)
In response to FIREking
del x follows OOP standards, whereas del(x) does not. Technically then, its always been the preferred way, but BYOND didn't support the better syntax at first. It was added at some point. If I remember correctly, there's a note about it in whatever release notes it was added in, but I don't have the time to find it.

Anyway, thats not causing the problem.

-AbyssDragon
In response to Spuzzum
I never knew there was a difference between sleep(1) and spawn(1) in a situation like that. Thanks for the clear up. The code works perfectly now.
In response to Lord of Water
Lord of Water wrote:
I never knew there was a difference between sleep(1) and spawn(1) in a situation like that. Thanks for the clear up. The code works perfectly now.

Yep. A sleep() just makes the current code stop temporarily, while a spawn() runs some other code after the specified time limit while it continues to run the current code. spawn() always requires a block of code or a proc call to go with it.