ID:264546
 
Hello, How do I code it so, when a persons's lifespan decreases the bar in the skin that i made decreases too..


heres a screenie.



Photobucket


heres the code



 mob/proc
lifespan()
if(lifespan)
..()
else
LifeSpanTime()
winset(src,"lifespan","text-=[src.lifespan]")
mob
var
lifespan=0


mob/proc
LifeSpanTime()
loop
sleep(10)
winset(src,"lifespan","value-=6")
lifespan-=6
spawn(1)
goto loop



It doesn't work... I dont know why.. And also for teh Hp bare it does the same.. please help
In response to Jemai1
didn't help because they didnt tell me anything about what i just asked.
In response to Yukay Karyuu
mob
var
max_lifespan = 1234
lifespan = 1234

proc/lifespanloop()
while(lifespan>0)
sleep(10)
ASSERT(max_lifespan)
lifespan = min(max_lifespan,max(0,lifespan-6))
var/percent = lifespan*100/max_lifespan
winset(src,"lifespan","value=[percent]")


Seriously,
http://www.byond.com/developer/articles/start

Code Edited.
In response to Jemai1
Lifespan.dm:25:error:ASSSERT:undefined proc
Lifespan.dm:27:percent :warning: variable defined but not used
In response to Yukay Karyuu
Oh, sorry. I don't use DM to compile and see what a simple code does. Mistakes happen. :)
In response to Jemai1
Save yourself some processing, call the health bar to update when needed, not every single second!

[link]
In response to GhostAnime
GhostAnime wrote:
Save yourself some processing, call the health bar to update when needed, not every single second!

[link]

Huh?
In response to Jemai1
Basically, only call an update proc when you need to, for this example in situations where the player takes damage
In response to Jotdaniel
If the OP has both a 'lifespan' and a 'health' bar in his rip, doesn't that indicate that lifespan might not be damage related?

It seemed like a counter to me, in which case the solution presented would indeed be decent (update when the lifespan is altered, though you could argue that you should store the old percent value and only winset when that changes, since the example maps 1024 on 100).


At Jemai1:
As for the code snippet and the advice to read the guide, this is contradicting.
If you feed a help vampire with copy and paste-able code, it is most likely going to blindly leech instead of learning.
If you want to teach, you will have to help the vampire step by step and correct it's misunderstandings.
I tried it on the pager, until suddenly there was no more incentive to follow my words, since you had posted a copy and paste-able solution and the communication died right away on the spot.
In response to Schnitzelnagler
The sample was not intended to be copy and paste-able. But, still, my bad.

I'll keep that in mind.

In response to Jemai1
Jemai1 wrote:
The sample was not intended to be copy and paste-able.

The sheer sight of a code snippet, is to a help vampire, like a bait for a fish. It will jump at it without a second thought, without trying to understand what you did or had in mind.

The next reply is
...eithere.g. [link]:
codefile_name.dm:line:error:what_went_wrong
repeat x times
codefile_name.dm:line: something :warning: warning_message
repeat y times
...or:
Thanks, it works, I learned a lot.

The first means that the vampire failed to copy and paste the code snippet in a way that it is compatible with the other code snippets the vampire had copy and pasted there before.

The second means that copy and pasting went well, there are no compile time errors and the first test proved it does nearly what the vampire wanted to do, now the vampire can go ahead and search for more code snippets to complete 'it's own game'.

Funny story...
I once 'quoted' part of a help vampires own code snippet, to hint at some mistakes.
The reply was that my code won't work. The vampire did not even realise that it was it's very own code when blindly copy and pasting.
In response to Schnitzelnagler
Nobody still hasn't helped me out here.
In response to Yukay Karyuu
If you had carefully read through the example Jemai1 provided in his reply[link], then compared the arguments winset takes (like I advised on the pager) and tried to understand what he did and why he did it this way, you would have a fully functional solution by now.
In response to Schnitzelnagler
This is what i have..



 mob/proc // To start off the code for the proc
lifespan()// The name of the proc in which i will use to start as the player logs in
LifeSpanTime()// The Proc that I will use to spawn the lifespan decreasing
winset(src,"lifespan","value=[src.lifespan]")// A Code that i think should make the lifepsna bar in skin decrease it's value going along with the lifespan's var.. Say Lifespan was 100.. then it decrease to 500 i expect it to go at a half bar.. but it does not



mob/proc
LifeSpanTime()// The name of the proc
loop
while(lifespan>0)
sleep(10)
ASSERT(max_lifespan)
var/percent = min(max_lifespan,max(0,lifespan-6))
winset(src,"lifespan","value=[percent]")
spawn(1)
goto loop

mob
var
max_lifespan = 1234
lifespan = 1234

proc/lifespanloop()
while(lifespan>0)
sleep(10)
ASSERT(max_lifespan)
var/percent = min(max_lifespan,max(0,lifespan-6))
winset(src,"lifespan","value=[percent]")
In response to Yukay Karyuu
If you did read what I said (I kind of doubt that ;)), what is the name of your 'Lifespan'-bar element and is it unique?
In response to Schnitzelnagler
lifespan id is called "lifespan" and what do you mean unique?