ID:1855568
 
(See the best response by FKI.)
I'm using Foomer's Fade library. I won't post his entire code so it doesn't take up space in this post but I'll post what I hope helps you help me.

/ Each new client gets its own map_fade object.
client/New()
..()

src.screen += new/map_fade


// This is the fade object that is used by the library - each client gets one.
// It will automatically be added to the client's screen and it will change
// truanslucency dependant on the client's current fade settings.
map_fade
parent_type = /atom/movable

icon = 'fade_gradient.dmi'
icon_state = "0"

screen_loc = "NORTHWEST to SOUTHEAST"

// Defaults to 255, but this can be altered with the fade.MapLayer() proc.
layer = 90001



My Code:
mob/proc/Daystart() //I made each of these 'mob/proc' it affects mobs.
fade.Map(src, 63, 2, 50) //from 12am to 3
mob/proc/Dayend()
fade.Map(src, 127, 2, 50) //from 3 to 6
mob/proc/Sunsetstart()
fade.Map(src, 191, 2, 50) //from 6 to 9
mob/proc/Sunsetend()
fade.Map(src, 255, 2, 50) //from 9 to 12am
mob/proc/Nightstart()
fade.Map(src, 191, 2, 50) //from 12am to 3
mob/proc/Nightend()
fade.Map(src, 127, 2, 50) //from 3 to 6
mob/proc/Sunrisestart()
fade.Map(src, 63, 2, 50) //from 6 to 9
mob/proc/Sunriseend()
fade.Map(src, 0, 2, 50) //from 9 to 12pm

proc/DayCycle() //This proc is called under World/New() so it starts when the world is online.
daytime = "Day" //var/daytime is already declared elsewhere in the code. It's displayed to all mobs with clients in their Status tab

sleep(10) //using sleep() instead of spawn() so these procs are run in order
for(var/mob/M in world) //this is where I thought the Night/Day system would affect mobs :(
if(!M.client) return
M.Daystart()
daytime = "Afternoon"

sleep(10)
for(var/mob/M in world)
if(!M.client) return
M.Dayend()
daytime = "Evening"

sleep(10)
for(var/mob/M in world)
if(!M.client) return
M.Sunsetstart()
daytime = "Dusk"

sleep(10)
for(var/mob/M in world)
if(!M.client) return
M.Sunsetend()
daytime = "Night"
Day++ //This var is declared elsewhere
YearCheck() //This proc is declared elsewhere. It just checks what number day it is and if it's 32, it brings Day==1 and raises the
//Month var by 1 increment, then checks to see if the month==12, and if it is it makes month==12,and raises the Year var by 1 increment.

sleep(10)
for(var/mob/M in world)
if(!M.client) return
M.Nightstart()
daytime = "Early Morning"

sleep(10)
for(var/mob/M in world)
if(!M.client) return
M.Nightend()
daytime = "Dawn"

sleep(10)
for(var/mob/M in world)
if(!M.client) return
M.Sunrisestart()
daytime = "Morning"

sleep(10)
for(var/mob/M in world)
if(!M.client) return
M.Sunriseend()
DayCycle() //repeats the Daycycle() proc


Problem description: Hey there. I know my code isn't the most efficient/best night/day method. It has no errors, but it doesn't work. I made sure the layer of map_fade(in Foomer's code) was higher than every other layer (I'll worry about interior areas later). It just doesn't really initialize from what I can see. After waiting about 20 seconds I'll right click the map (during runtime) and check the edit sheet of map_fade and it's icon_state is still 0 (which is when it's clear as day). I don't know why it doesn't cycle through the day.

In your for() loops, you're returning the whole proc as soon as it hits a mob with no client. If you want to skip to the next iteration, you should be using the "continue" keyword instead.
In response to Kaiochao
Kaiochao wrote:
In your for() loops, you're returning the whole proc as soon as it hits a mob with no client. If you want to skip to the next iteration, you should be using the "continue" keyword instead.


That worked to an extent. Now with this code, during runtime it pretty much stops after daytime=Afternoon. Then the daytime goes back to "Day" and it just flops back and forth from Afternoon to Day. :/

proc/DayCycle()
daytime = "Day"

for(var/mob/M in world)
if(!M.client) continue
if(daytime == "Day")
M.Daystart()
daytime = "Afternoon"

for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Afternoon")
M.Dayend()
daytime = "Evening"

for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Afternoon")
M.Sunsetstart()
daytime = "Dusk"

for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Dusk")
M.Sunsetend()
daytime = "Night"
Day++
YearCheck()

for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Night")
M.Nightstart()
daytime = "Early Morning"

for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Early Morning")
M.Nightend()
daytime = "Dawn"

for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Dawn")
M.Sunrisestart()
daytime = "Morning"

for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Morning")
M.Sunriseend()
DayCycle()

Ahoy! I believe I fixed the problem. It works fine now with this code. Could you tell me if I could make this better in regard to lag reduction? Because I don't know how it will perform when my game is online people start connecting to it if they don't find it to be a crap game. =o

proc/DayCycle()
spawn while(1)

daytime = "Day"
for(var/mob/M in world)
if(!M.client) continue
if(daytime == "Day")
M.Daystart()
daytime = "Afternoon"
sleep(1)
for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Afternoon")
M.Dayend()
daytime = "Evening"
sleep(1)
for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Evening")
M.Sunsetstart()
daytime = "Dusk"
sleep(1)
for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Dusk")
M.Sunsetend()
daytime = "Night"
Day++
YearCheck()
sleep(1)
for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Night")
M.Nightstart()
daytime = "Early Morning"
sleep(1)
for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Early Morning")
M.Nightend()
daytime = "Dawn"
sleep(1)
for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Dawn")
M.Sunrisestart()
daytime = "Morning"
sleep(1)
for(var/mob/M in world)
if(!M.client) continue
if(daytime=="Morning")
M.Sunriseend()
For starters, instead of searching the world's contents for mobs, make a separate list with all client-connected mobs in it and search that.
In response to FKI
FKI wrote:
For starters, instead of searching the world's contents for mobs, make a separate list with all client-connected mobs in it and search that.

Perfect idea. Except I'm completely stumped right now. I made what I could think of but I'm drawing a blank. Am I on the right path with this so far?

var/tmp/list/PlayersOnline=list()
var/tmp/Players=0

mob/Login()
if(!m.client) return
Players++

mob/Logout()
if(!m.client) return
Players--
In response to Oleic
Best response
Close. An example:

var/list/players

mob
Login()
..()
if(!players)
players = list()
// this adds 'src' to the players list if not already present (for whatever reason)
players |= src

Logout()
players -= src
if(!players.len)
players = null
..()


You probably shouldn't be stopping Logout() with that client check (it doesn't look necessary at all). The client has already disconnected by that time, so that check is going to return true most of the time.
I just replaced all relevant lines of code that had 'in world' with 'in players' and it works great. Thanks man.