ID:142185
 
Code:
                                    var/E = new/obj/beam/kameha01
E:icon +=rgb(usr.red,usr.green,usr.blue)
usr.overlays += E
var/F = new/mob/bullet(usr.loc)
F:lasthit = usr.key
F:dir = usr.dir
F:owner = usr.key
F:red = usr.red
F:green = usr.green
F:blue = usr.blue
if(usr.dir == NORTH)
F:y += 1
if(usr.dir == SOUTH)
F:y -= 1
if(usr.dir == EAST)
F:x += 1
if(usr.dir == WEST)
F:x -= 1
F:beam = 1
F:beamtype = 1
F:damage = usr.powerlevel/20
if(F:damage <=0)
F:damage = 1
F:owner = "[usr.key]"
F:name = "Kamehameha Wave"
F:icon = 'kamehame(release).dmi'
F:icon_state = "end"
F:icon +=rgb(usr.red,usr.green,usr.blue)
walk(F:,usr.dir,2)
sleep(50)
usr.overlays -= E
usr.icon_state = ""
usr.moves = 0
usr.attacking = 0


Problem description:

var/E = new/obj/beam/kameha01


^
|
|
|
Thats the source of my problem.

Currently,my attack for my game is custom colored,meaning you can input the rgb values.

Problem is that I don't know how to remove the E.overlay incase you logout while shooting the attack,since I have it set to an individual variable,and when I try to do
src.overlays -= /obj/beam/kameha01


Upon logout,when I log back in,its still stuck on my character.

Any ideas?

usr.overlays -= E


That works just fine,after the attack is done,but it doesn't seem to work if I add that line to my logout proc.

This is because, while there are multiple methods of adding an overlay (type path, /image object, /atom object...), you need to use the same method to remove that said overlay later. If you've used an /obj object to add the overlay, you can't remove it with a type path afterwards. You need to use the same object. It won't magically work if you put src.overlays -= E somewhere else, since E is a local variable specific to your attack routine, so you can't use it anywhere else.
It'd be useful to read the DM Guide before proceeding. Also make sure you use the DM Reference a lot (available from the link or by pressing F1 in Dream Maker).

Your code uses the : operator a lot. It is generally unsafe, and should never be used for the most part. There is no reason to use it instead of '.' in your code, you should simply define your variables' types properly.

Also, if you have something like this:
                                    if(usr.dir == NORTH)
F:y += 1
if(usr.dir == SOUTH)
F:y -= 1
if(usr.dir == EAST)
F:x += 1
if(usr.dir == WEST)
F:x -= 1

You should use 'else-if' instead; because if you already confirmed that dir equals NORTH, there is no reason and it is silly to still check if it also equals SOUTH,EAST or WEST which is of course impossible. An even better approach would be to use switch() -- although in this case, you're not even approaching it quite right; you should just use get_step() for that, and your entire projectile implementation is quite off. You should handle it more systematically and dynamically in procs and by using object subtypes instead of the way you have it now, hardcoding it into every verb (or whatever). Also, don't identify objects or keep track of them by their name; just use the object reference (ie 'the object itself') instead which is much more useful:
F.owner = usr
Whoa, whoa, whoa. There's a good rule of thumb for a beginning DM programmer: "If I have to use the colon operator or goto, I'm doing something wrong."

Before we get to your problem, let's take a look at typecasting. When you define variables for any datum, they belong to a specific type path. In this particular case, your mob/bullet has (at least) five variables that you defined, as well as several atom variables such as icon and name. When you're "forced" to use the colon operator to access any of these, then you are improperly typecasting (or in your case, not at all).

This line in your code:
var/F = new/mob/bullet(usr.loc)

with a simple modification can remove the need for using the colon operator altogether. If we define F as follows:
var/mob/bullet/F = new(usr.loc)

Then you have typecasted this variable. Thusly, in later segments of code, you can use the period property accessor (.) instead of the colon search operator(:), such as:
F.lasthit = usr.key
F.dir = usr.dir
F.owner = usr.key
F.red = usr.red
F.green = usr.green
F.blue = usr.blue

Why is that better? Because the variable/proc doesn't actually have to exist to call it with the colon operator, it becomes increasingly difficult to track down buggy code. By typecasting, you're catching several bugs at compile-time instead of at runtime, not to mention it's simply better programming practice.

As for your issue at hand, you have to store the object reference to be used later. Something like:
mob/var/tmp/obj/beam/kameha01/kamehameha_thing //need to define the variable first

mob/verb/fire_kamehameha()
if(!src.kamehameha_thing) //if they're not firing one already
src.kamehameha_thing = new
src.kamehameha_thing.icon += rgb(src.red,src.green,src.blue)
src.overlays += src.kamehameha_thing
//fire the kamehameha
src.overlays -= src.kamehameha_thing
src.kamehameha_thing = null

Now you've stored the object reference and can use it later. Simply remove kamehameha_thing from the mob overlays if they log out while firing later.

I also seriously hope this is a mob/verb that this code is in, otherwise you're abusing usr as well.
In response to Mobius Evalon
Mobius Evalon wrote:
Whoa, whoa, whoa. There's a good rule of thumb for a beginning DM programmer: "If I have to use the colon operator or goto, I'm doing something wrong."

Before we get to your problem, let's take a look at typecasting. When you define variables for any datum, they belong to a specific type path. In this particular case, your mob/bullet has (at least) five variables that you defined, as well as several atom variables such as icon and name. When you're "forced" to use the colon operator to access any of these, then you are improperly typecasting (or in your case, not at all).

This line in your code:
> var/F = new/mob/bullet(usr.loc)
>

with a simple modification can remove the need for using the colon operator altogether. If we define F as follows:
> var/mob/bullet/F = new(usr.loc)
>

Then you have typecasted this variable. Thusly, in later segments of code, you can use the period property accessor (.) instead of the colon search operator(:), such as:
> F.lasthit = usr.key
> F.dir = usr.dir
> F.owner = usr.key
> F.red = usr.red
> F.green = usr.green
> F.blue = usr.blue
>

Why is that better? Because the variable/proc doesn't actually have to exist to call it with the colon operator, it becomes increasingly difficult to track down buggy code. By typecasting, you're catching several bugs at compile-time instead of at runtime, not to mention it's simply better programming practice.

As for your issue at hand, you have to store the object reference to be used later. Something like:
> mob/var/tmp/obj/beam/kameha01/kamehameha_thing //need to define the variable first
>
> mob/verb/fire_kamehameha()
> if(!src.kamehameha_thing) //if they're not firing one already
> src.kamehameha_thing = new
> src.kamehameha_thing.icon += rgb(src.red,src.green,src.blue)
> src.overlays += src.kamehameha_thing
> //fire the kamehameha
> src.overlays -= src.kamehameha_thing
> src.kamehameha_thing = null
>

Now you've stored the object reference and can use it later. Simply remove kamehameha_thing from the mob overlays if they log out while firing later.

I also seriously hope this is a mob/verb that this code is in, otherwise you're abusing usr as well.

Yes its a mob/verb,but I'll try doing it your way,thanks alot.