ID:175096
 
We have this game that, after an hour or two of being up on a public server, more or less chokes and people who enter the game cannot sign in to their characters. It's pretty consistent too.

Could this be due to some coding in the game, or is the game too large, or is it the server? Does anyone have any idea? Could it be caused by run-time errors? We're lost...

-Dagolar
If there are a LOT of variables in the game attached to a LOT of mobs/objs and so on, does that slow down the game a lot and possibly make it shut down?

-Dagolar
In response to Dagolar
I hope not, Im going to make Dynasty Warriors Online, do you know how many mobs there will be?!?
In response to Nave
Well, if it becomes necessary there are always ways to can setup the game to work without everything existing all at once. In other words, objs and mobs might be saved and removed when a certain area becomes inactive, and restored when a player enters that area again. Then they don't have to exist idly while the area is totally unused.
In response to Foomer
What I mean is about all the variables? Here's what I mean.
When a player makes a character, there are something like 40 variables attached to that character. Statistics, which missions have been completed, which bosses have been knocked off, and so on. Can this create problems with the game running?

-Dagolar
In response to Dagolar
I don't know, and I'm not sure there are too many people that would, since its internal BYOND stuff that would cause a crash or a shutdown. Only thing I can suggest is that you use lists to store missions completed and bosses defeated :P

<code>mob/var stat1 stat2 stat3 list/missions = list() list/bosses = list() proc/EncounterBoss(mob/M, boss/B) if(M.bosses[B.name]) M << "[B] has already been defeated." else M.Encounter(B)</code>

:P

In response to Foomer
That's not a bad idea. I haven't used a single list in my variables. They're all separated. Would it solve a lot of lag to put a lot of it into lists?

-Dagolar
In response to Dagolar
I don't think lag is caused by variables. It just makes it much more convenient to access, in my opinion, and you don't have to create a new variable for each new mission or boss, since the list either has it or doesn't.
In response to Foomer
Well here's a verb that displays all the players in the game. It's very slow to display, almost choppy.

who()
set category="Commands"
usr<<"List of Players:"
for(var/mob/M in world)
if(M.client)
usr<<"\icon [client] [M.name]([M.key]) - \red L [M.Level] [M.Class]\black - House: [M.Guild]"


Is there a way to identify only clients. Because if the if(M.client) line is removed, it displays ALL mobs, including monsters. Maybe a list would be better? I'm trying to remove lag producing verbs and variables, because the game has been on the hub and just stops working after a couple of hours...

-Dagolar
In response to Dagolar
Dagolar wrote:
What I mean is about all the variables? Here's what I mean.
When a player makes a character, there are something like 40 variables attached to that character. Statistics, which missions have been completed, which bosses have been knocked off, and so on. Can this create problems with the game running?

-Dagolar

If you have a lot of flags(yes/no or true/false) type variables it's best to just pack 16 of them in one variable by setting and clearing bits.

Here are some useful macros for doing this.
#define SET_BIT(VAR,BIT)            VAR |= (BIT) 
#define CLEAR_BIT(VAR, BIT) VAR &= !(BIT)
#define CHECK_BIT(VAR, BIT) ((VAR) & (BIT))



Then to use these you'd do something like
//Make sure the first flag starts at two and each one after is two times the last.

#define KILL_THE_DRAGON 1
#define SAVE_THE_PRINCESS 2
#define BEAT_THE_BIG_BAD_GUY 4

var/questflags

//----------------------------------
//Somewhere in someones conversation
//----------------------------------

//To check one flag you can do something like
if(CHECK_BIT(questflags, KILL_THE_DRAGON))
view() << "Hail the great dragon slayer!"

//To check if atleast one of the flags is set you can do
if(CHECK_BIT(questflags, KILL_THE_DRAGON | SAVE_THE_PRINCESS | BEAT_THE_BIG_BAD_GUY))
view() << "Hail the hero!"
else
view() << "Who are you?"

//----------------------------------
// Somewhere in the dragon death source code
//----------------------------------

//To set one bit you do
SET_BIT(questflags, KILL_THE_DRAGON)

//Or if you want to set a few flags
SET_BIT(questflags, KILL_THE_DRAGON | BEAT_THE_BIG_BAD_GUY)


//----------------------------------
// Some source code triggered after a long time
//----------------------------------

//Everybody forgot the deeds of the player

CLEAR_BIT(questflags, KILL_THE_DRAGON | BEAT_THE_BIG_BAD_GUY | SAVE_THE_PRINCESS)



If you do this you can dramatically opimise memory usage in your game.
In response to Theodis
That's a revamp and a half. :|

- Dagolar
In response to Dagolar
Dagolar wrote:
That's a revamp and a half. :|

- Dagolar

But it's well worth it and very memory effecient. Even if you don't use this in your current game keep it in mind for the next. Since the less variables you have the less bandwidth and system memory your game takes. If you replace 16 variables with one that is a major bosst in effeciency.
In response to Dagolar
Dagolar wrote:
Is there a way to identify only clients.

Clients are objects too, you know. =)

<code>for (var/client/C) //Don't put "in world"! Clients are never "in the world".</code>

Because if the if(M.client) line is removed, it displays ALL mobs, including monsters. Maybe a list would be better?

Yes, it would be better. Looping through a list is much faster than looping through the world.

<code>var/clientlist[0] client/New() .=..() if (.) clientlist+=src client/Del() clientlist-=src .=..()</code>

You can do similar things with various types of atoms, too. So if you often loop through all the mob/enemy/monster objects in the world, then do the above but replace "client" with "mob/enemy/monster".