• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

player.Save() used with Game.getPlayers() - Thoughts?

Exeus

Advanced OT User
Joined
Oct 8, 2012
Messages
859
Reaction score
198
Let's assume that I'd want to use something like this:
Lua:
while(true)
   do
       local t = Game.getPlayerCount()
       local arr= Game.getPlayers()
       for i=1,t
       do
           player = arr[i]
           player:save(player)
           wait(1000)
       end
       wait(900000)
   end

1: How to create those waits?

2: How hard it'd affect CPU usage or generally "server's" performance?
(ik ik, kinda specs dependent but let's ignore it)

3: Is there any other and better way to save players' state "on the fly"?
 
Solution
Let's assume that I'd want to use something like this:
Lua:
while(true)
   do
       local t = Game.getPlayerCount()
       local arr= Game.getPlayers()
       for i=1,t
       do
           player = arr[i]
           player:save(player)
           wait(1000)
       end
       wait(900000)
   end

1: How to create those waits?

2: How hard it'd affect CPU usage or generally "server's" performance?
(ik ik, kinda specs dependent but let's ignore it)

3: Is there any other and better way to save players' state "on the fly"?

1. Lua does not have a sleep / wait function with loops

2. Well you are looping but other then that nothing?

3. Yes, not sure why you use getPlayerCount, try this;
Lua:
for _, player in pairs(Game.getPlayers())...
Let's assume that I'd want to use something like this:
Lua:
while(true)
   do
       local t = Game.getPlayerCount()
       local arr= Game.getPlayers()
       for i=1,t
       do
           player = arr[i]
           player:save(player)
           wait(1000)
       end
       wait(900000)
   end

1: How to create those waits?

2: How hard it'd affect CPU usage or generally "server's" performance?
(ik ik, kinda specs dependent but let's ignore it)

3: Is there any other and better way to save players' state "on the fly"?

1. Lua does not have a sleep / wait function with loops

2. Well you are looping but other then that nothing?

3. Yes, not sure why you use getPlayerCount, try this;
Lua:
for _, player in pairs(Game.getPlayers()) do
    player:save()
end
 
Solution
1. Lua does not have a sleep / wait function with loops

2. Well you are looping but other then that nothing?

3. Yes, not sure why you use getPlayerCount, try this;
Lua:
for _, player in pairs(Game.getPlayers()) do
    player:save()
end

Thanks for answering

I mean... It won't be 'too fast'?
Let's assume that we have 600+ players online, then it won't create huge lags?
Saving every character online every Xsec?

as I see I'll have to think about it again :p
 
Last edited:
1. Lua does not have a sleep / wait function with loops
what about coroutines? lua itself has, but wouldn't work for tfs, since Lua runs on same game thread.
1: How to create those waits?
you can't in lua because lua events runs on same thread as game events, just one event can happen at same time, one need to finish to other start, but you can schedule you events with addEvent function.
 
Thanks for answering

I mean... It won't be 'too fast'?
Let's assume that we have 600+ players online, then it won't create huge lags?
Saving every character online every Xsec?

as I see I'll have to think about it again :p

Well saving in stages can also be dangerous, duplicated items etc etc
Would be better to test it and see if it works :p

what about coroutines? lua itself has, but wouldn't work for tfs, since Lua runs on same game thread.

Correct they work on the same thread, so no major diffrence.
 
Back
Top