ID:140647
 
Code:
obj
glimmer
icon = 'DevilFruitPowers.dmi'
icon_state = "Glimmer"
density = 0
var/owner
var/time= 0 // under obj/ball since only ball needs it
Bump(mob/M)
if(istype(M)) // type check
M.hp -= time
time=0 // make the ball time 0 so it'll delete itself ? Your call
New(loc,timechosen,owner) //Receive the time chosen by the creator of the ball
src.time=timechosen
spawn() time()
src.owner = owner
..()
proc
time() // this can be under obj/ball since that's where you need the time()
while(src.time > 0)
sleep(10)
src.time -= 1
if(src.time <= 0)
usr.GlimmerPets = null
del(src)
Click()
switch(input("What do you want to do?","choose") in list("Density","Manipulate Area","Cancel"))
if("Density")
if(src.density != 1)
src.density = 1
usr << output("The Element is now dense","SM")
return
else
src.density = 0
usr << output("The Element is now undense","SM")
return
if("Manipulate Area")
if(src.mparea != 1)
src.mparea = 1
else
src.mparea = 0
if("Cancel")
return
Move()
if(src.mparea == 1)
var/time = src.time + 10
new/obj/light( src.loc,time)
return ..()

obj
light
icon = 'Turf.dmi'
icon_state = "Light"
density = 0
var/time = 0
New(loc,timechosen) //Receive the time chosen by the creator of the ball
src.time = timechosen
spawn() time()
..()
proc
time() // this can be under obj/ball since that's where you need the time()
while(src.time > 0)
sleep(10)
src.time -= 1
if(src.time <= 0)
del(src)
Entered(mob/M)
if(M.power == "glimmer glimmer")
return
else
M.entere = 1
while(M.entere == 1)
sleep(5)
var/damage = time * 1.75
M.hp -= damage
if(M.hp <= 0)
M.Deathcheck()
return
Exited(mob/M)
M.entere = 0
return


mob/var/tmp/entere = 0

obj
var
mparea

mob
var/tmp/list/GlimmerPets

mob/glimmer
verb
Extract_Element()
var/time=input("how much energy do you want to put in the extracted element?","energy")as num
if(time > usr.energy)
usr << output("You do not have enough energy!","SM")
return
var/obj/glimmer/G = new(get_step(src,NORTH),time)
// G.loc=locate(src.x,src.y+1,src.z)
// G.time =time
usr.energy -= time
if(!usr.GlimmerPets)
GlimmerPets= new()
GlimmerPets+=G


Problem description: Hello, I have this code bit here in which i create an element, basically an object, called glimmer, which i then want to last for a certain amount of time based on how much energy you put in to it. i want to be able to move it around by clicking on the screen. and i want it to delete itself when the time has reached 0.

Now: First of all i would like anyone who could to see trough this probably insufficient bit of coding and if you could, please correct it, make it better in therms of sufficiency if possible.

Second: it seems to be working ok, but sometimes when i change it to the "manipulate" area, where it is supposed to make these traces of light appear on the turfs.

It sometimes either starts lagging or even fails to delete these, as they too are supposed to be deleted when their time is over.

Another thing is that when someone else with the same "powers" creates this object and starts manipulating the areas.. it seems as if the one that i created previously or visa versa, somehow is "resurrected" and all of the sudden there are two of these glimmer objects making traces of glimmer (these traces are basically just a 32x32 pixel light colored square) and are placed as the glimmer moves.


Anyone know why this might be ?
I would appriciate if someone fixed this coding so that it would work properly, but i know it's probably asking for abit too much.

Thanks for your time

Regards
Narutostory


You need to be a lot more specific about your errors if you want help with them. Regardless, I can provide a few specific areas that need improvement.

First, you declared an owner variable, but aren't using it. You need to change it to var/mob/owner, and then you need to replace the usr in time() with owner. You'll also need to add a third argument when creating the object, because you currently aren't doing that.

Next, you do NOT need those if() statements inside the while() loops. Remove them, and place the code that was within them to be AFTER the while() loop. So, you'd have:

while(src.time > 0)
sleep(10)
src.time -= 1
if(owner)
owner.GlimmerPets -= src
del(src)


I also changed usr to owner, checked to see if they still exist (for example, they wouldn't if the player logs out while having one of these out, which would cause an error), and had it remove from the list instead of nulling it out. You'd do something similar for the light's time() proc.

Oh, and even though it won't technically change anything, you should move the call to time() to the last line of New(), as that makes more sense conceptually.

Also, for your /obj/light, the Entered() and Exited() procs won't do what you think they should: those are called when a movable enters an atom's contents, and so generally are only called for turfs. You will need to write a SteppedOn() proc (search the forum for that) for something like that. Oh, and the loop will start multiple times if you walk through a trail of those lights, causing rather large amounts of damage, and if one disappears while you're standing on it, you have no way of stopping the damage.

As for your problem of "resurrecting" glimmers, you need to provide a very specific description of what happens to cause the bug or we can't help.
In response to Garthor
it might just so be that you have solved all my problems in your post there :)

sorry for my bad problem descriptions. What you have pointed out however seem like they can be the reasons to my problems.
Once i get time to do so i will make the changes and reply with the results. but i have a good feeling this fixes the problem.