ID:265400
 
I have recently been told that using an ongoing proc will cuase lag. This happened to me in one of my pervious games. For example
mob
AI
New()
spawn(5) src.Wander()
proc
Wander()
while(src)
sleep(10)
walk(rand,src)

Thats a "little demo" version to give you an example of what I am using. Will this cuase lag?

Is there a better way to make a ongoing procs for enemies?
ITG Master wrote:
I have recently been told that using an ongoing proc will cuase lag. This happened to me in one of my pervious games. For example
> mob
> AI
> New()
> spawn(5) src.Wander()
> proc
> Wander()
> while(src)
> sleep(10)
> walk(rand,src)
>

Thats a "little demo" version to give you an example of what I am using. Will this cuase lag?

Is there a better way to make a ongoing procs for enemies?

Ref,er!ance ... dang straight. Cause you have to say it like that. With the stop and ! mark.

See topic ["background setting (proc)"] :)
In response to Green Lime
So by setting

set backround = 1

That would stop the proc from cuasing lag!? Yes!
In response to ITG Master
ITG Master wrote:
So by setting

set backround = 1

That would stop the proc from cuasing lag!? Yes!

O.o did you even read the reference information? If you did, go back and read it again.

As for lag goes any thing you do causes lag. No matter what. Lag exist within any network game. I dont care if its a ping pong game being run over a 1000GB transfer. Whats that a tetra byte I think. Now the most effcient way to handle your lag is basically up too you. Since code on byond can differ so much there is no set standard.

Setting background will make your procedure run in ... O.o the background. So as it says in the reference, any pending actions will be taken. Then the procedure would start up again. So if you had a loop such as you did and you set it in the background. It would allow any other functions to go with out being bogged down by that procdure.

I suggest looking up the spawn() and sleep() functions as well. I think the sleep() function may give you more control ability. That is than just setting the background.

"Calling sleep() with a negative argument (such as sleep(-1)) causes it to do a backlog check. Only if other pending events have become backlogged will it sleep. This is similar to running in the background, but you manually control where the backlog checks are made. The difference between this and sleep(0) is that sleep(0) always sleeps the current procedure for as short a time as possible, whereas sleep(-1) only sleeps the current procedure if other scheduled events have become backlogged. Therefore, sleep(-1) will tend to run the current procedure at a higher priority with fewer interruptions. It is appropriate when there is a single task that needs to be done before anything else can happen, and you just want to make sure that network and user I/O are not terribly lagged in the process" - from the sleep() reference.

O.o does that help?
In response to Green Lime
"As for lag goes any thing you do causes lag. No matter what. Lag exist within any network game. I dont care if its a ping pong game being run over a 1000GB transfer. Whats that a tetra byte I think."

I seriously doubt that running Pong over a terabyte connection would cause lag... :p
In response to Elation
Elation wrote:
"As for lag goes any thing you do causes lag. No matter what. Lag exist within any network game. I dont care if its a ping pong game being run over a 1000GB transfer. Whats that a tetra byte I think."

I seriously doubt that running Pong over a terabyte connection would cause lag... :p

It would, it'd just be uber-highly (bolding random words is fun) unnoticable.
In response to Hell Ramen
Well, what would happen was..after running the game for about 9000 ticks it would start to get UBER LAGGY, to the point of no moving. If I add the set backround = 1, would I reduce that? BTW my procs do use sleep and spawn.
In response to ITG Master
Instead of asking if it will work, just give it a whirl. You can't break you program or anything. There's no better way to find out then by doing it yourself.

Prodigal Squirrel
In response to ITG Master
No, setting background would probably not fix it. Look elsewhere for your lag. =)
In response to Crispy
Crispy wrote:
No, setting background would probably not fix it. Look elsewhere for your lag. =)

Crispy O.o do you think you could write a Byondscape Stringer on how this could be used. This and sleep(-1)/sleep(0).

Psst, try:
mob
AI
New()
spawn(5) src.Wander()
proc
Wander()
while(src)
sleep(10)
step_rand(src)


That should reduce lag, calling walk multiple times is probably what's making it crash. Or, you could just get rid of the loops and use walk_rand(src).
In response to Prodigal Squirrel
The problem is, I would have to sit here staring at my screen for about 30 mins for the lag to kick in....and I don't want to do that. SO I will just go back and relook my code.
In response to Green Lime
I think what he's trying to say is, there is no magical fix for bad programming. Setting it to the background will only make the world wait to execute it after the other stuff is done. It's not going to make the usage disappear.
In response to SSJ2GohanDBGT
I don't have bad programming. I just have never had to deal with loops before.

Don't reply to my posts if its not about the topic SSJ, I don't appreciate the rudeness.
In response to ITG Master
"Don't reply to my posts if its not about the topic SSJ, I don't appreciate the rudeness."

First off, how was that not about the topic? He was stating how putting it in the background is not a fix for lag. That seems very on the topic about causing lag to me.

Secondly, where was he rude? I really didn't think he was rude at all. All he said was that there is no instant easy fix for bad programming. He never stated that your programming was bad. Although, if it lags that much, you can certainly try to make it more efficient.
In response to Artekia
By saying I have bad programming skills? Should I take that as a compliment?
In response to ITG Master
Just because you mess up one thing doesn't necissarily mean your a bad programmer, just inexperienced. I myself am inexperienced. You learn as you go. If you REALLY want to fix your problem I recommend making the AI work only when a player can see it. Here's how your code is working:

1 mob : 1 loop
100 mobs : 100 loops

This is very bad. I'm not insulting you, nor was I trying to. I was just trying to help.
In response to ITG Master
"He never stated that your programming [inserted]abilities[/inserted] [slight change]are[/slight change] bad. Although, if it lags that much, you can certainly try to make it more efficient."

Although, as he said in his own post, he was just saying the way you were doing it was bad programming, not that you are a bad programmer in general.
Is there a better way to make a ongoing procs for enemies?

Having every mob run through a loop is a very bad idea especially if you have a lot of mobs. You'll kill a lot of CPU time doing a lot of nothing. It's best to avoid any sort of infinite loop aside from one event loop which handles periodic or timed functionality. For other stuff like AI it should be triggered or activated by some condition like a player moving in view or nearby and deactivating if there are no players in range. This way you can have thousands of mobs none of which will take any CPU time unless a player is around to actually see them do stuff.
In response to SSJ2GohanDBGT
SSJ2GohanDBGT wrote:
Just because you mess up one thing doesn't necissarily mean your a bad programmer, just inexperienced. I myself am inexperienced. You learn as you go. If you REALLY want to fix your problem I recommend making the AI work only when a player can see it. Here's how your code is working:

1 mob : 1 loop
100 mobs : 100 loops

This is very bad. I'm not insulting you, nor was I trying to. I was just trying to help.

Hmm couldn't you just do a 100mobs : 1 loop O.o
Page: 1 2