ID:1326021
 
(See the best response by Rushnut.)
Code:
var
AccTime = time2text(world.timeofday,"hh:mm:ss")
TimeofDay = ""
world
New()
..()
spawn(5)
Loop()
Update()
proc
Loop()
while(src)
sleep(10)
world.Repop()
Update()
..()
proc
Update()
while(src)
sleep(5)
AccTime = time2text(world.timeofday,"hh:mm:ss")
..()
area
icon = 'Floor.dmi'
icon_state = "night"
layer = EFFECTS_LAYER
New()
..()
spawn(5)
src.TimeoDay()
src.reboot()
proc
TimeoDay()
spawn(600)
if(AccTime=="4:00:00")
TimeofDay = "Morning"
..()
if(AccTime=="10:00:00")
TimeofDay = "Day"
..()
if(AccTime=="17:00:00")
TimeofDay = "Afternoon"
..()
if(AccTime=="20:00:00")
TimeofDay = "Evening"
..()
if(AccTime=="0:00:00")
TimeofDay = "Night"
..()


spawn(5)
src.reboot()
reboot()
spawn(5)
src.TimeoDay()


ok, so a couple of days ago, i realized how to create an effect(i note i didn't include all of the code, just what was directly imperative to the problem) on the world that it is night, and later that day, i had perfected turning it from day to night.

unfortunately that's where my good luck stopped.

As soon as i tried adding more 'Times of Day'(such as Morning, Afternoon, and Evening) the proc i used stopped working like it did.

originally the code called for the time having to be between certain hours of of the day, by using world.timeofday("hh:mm:ss") as a reference every minute.

i then switched it so that it was a one off at the time that it would change, nothing

then, to fix a slight error i saw in having it every minute, i changed it to update every second[spawn(10)], still didn't work

this is frustrating me to no end. None of my friends that code know any ideas to help, so i went to the one place i knew where a bunch of coders could provide some insight onto my headache


area
icon = 'Floor.dmi'
icon_state = "night"
layer = EFFECTS_LAYERNew() // <---- Not sure if this is because you pasted it?
..()
spawn(5)
src.TimeoDay()
src.reboot()


opps yeah, no i didnt paste that right, let me fix that
First of all, calling world.Repop() is a bad idea every second, it respawns everything in the world and will ultimately cause quite a bit of lag.


The problem is that you're not spawn()ing the Update() loop, so it's interrupting the other one and halting its operations.

    proc
Loop()
while(src)
sleep(10)
world.Repop()
spawn Update()



However having said that, having a while() loop spawning while() loops is NEVER a good idea, you should probably just move all of the Update() proc inside of the Loop() proc and call that only once.

Just to further optimize your koad, since you're only putting hooks for hour based intervals, you should probably only be calling the loop once an hour (Or half an hour).

Also calling ..() in a proc's definition does nothing (original comment do not steal).
i understand the lag part, that was mostly for testing purposes to make it work, i would have upped the spawn after initial testing to a speed i was comfortable with.


so your saying move the update out of the while(src), or add spawn? I'm slightly confused
Basically you have a loop that recurs infinitely, which is creating more infinitely recurring loops.

If you just spawn() the second loop, eventually your game will crash as more and more loops start to bog down the system.

You should either take the content out of the Update()'s while() loop and put it in the Loop()'s while() loop, or simply make Update() not have a loop.
ok...im going to try the first one, see if that works...which i cant properly test the time code as is, i will also up the spawn time to half a minute, for the time being.
In response to Bloody m
Bloody m wrote:
ok...im going to try the first one, see if that works...which i cant properly test the time code as is, i will also up the spawn time to half a minute, for the time being.

If you do up the spawn time to half a minute, you're going to want to make sure that you're on an hourly divisor, otherwise none of those if() statements will execute.
true, but if i down it too much, it will be all laggy like you said.

i am going to try it this way and a way that involves a line much like the following in place of the if(AccTime=="hh:mm:ss") lines

if(AccTime<="hh:mm:ss" && AccTime>="hh:mm:ss") of course the second part of the time being a later time(for instance, 4:59:59
You could instead just use time2text(etc,"hh")

I'm not 100% on if that would function properly but reading the documentation, it looks like it would.
Best response
To clarify, this is what I would personally do (Doing away with both your Loop(), Update() and reboot() procs)

        TimeoDay()
while(1)
var/timeHour = time2text(world.timeofday,"hh")
switch(timeHour)
if("04")
TimeofDay = "Morning"
if("69")
TimeofDay = "Wat"
sleep(600)
well, i still want loop to do the repop, so its probably not going anywhere...

however, i do like that idea, and it would probably save me time...
well, i wont know if it works for atleast 4 hours...so ill check back in then and give an update
You could simply set it to "mm" to debug...
?

i mean i won't be able to see the results I'm looking for until the next 'time change'

oh i got what you meant *slaps slef in face* my brain is off right now
So set the time changes to be every minute, and set the time2text to be "mm".


You can always change it back later, lol.
seem to still be having my main problem, it displays the time of day however, so that's a step in the right direction. i suppose i should add into the code(since right now that seems to be whats pointing to the in correction after all)

each line, right now has a slight alteration to the rgb, depending on the time of day, for example the one that should have just ran, afternoon has it set to src.icon+= rgb(153,51,0,161) but it did not change.
Icons can't directly be changed like that, they have to first be initialized and then edited, and then set... Or something like that. Maybe they can? Someone please correct me I have no idea what I'm saying.

What I know will work though:
var/icon/I = new(src.icon)
I.Blend(rgb(153,51,0,161))
src.icon = I



Edit: Oh right, the reason that doesn't work is because rgb() only returns a value, it doesn't actually do anything. Blend() actually modifies the icon, but can only be called on an icon datum which is why you first have to initialize it.

Or something.

Pudding.
hmm....for some reason i want pudding now...

anyway, I'm going to try that, however I'll rearrange it so i don't have to define I five times.
well, just waited to the next time change, nothing happened on screen, as usual. i guess i could change it so that the var/icon/I = new(src.icon) is in each of the lines not defined at the beginning of the proc... but it really doesnt seem like that will do anything.
Page: 1 2