• 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!

Lua How to use global storage in TFS 1.2?

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,529
Solutions
1
Reaction score
85
Location
Portugal
Hiho, like the title says could some1 explain me please how to set global storage in TFS 1.2?

Thanks in Advance <3
 
so with Game.setStorageValue I will be able to track for example total premium scrolls used on the server?

like
Code:
Game.setStorageValue(PACC_STORAGE, (Game.getStorageValue(PACC_STORAGE)+1))

Edit: doesn't work

Shouldn't Game.getStorage etc etc... be on this list?

YwsIAsf.png
https://i.imgur.com/YwsIAsf.png
 
Last edited:
If you are asking for help you should at least try to explain the problem you're facing. Simply stating that it "doesn't work" isn't helpful at all.

Both the Game.getStorageValue and Game.setStorageValue are defined in the data\lib\core\game.lua file. However the values you set with them are not persistent, meaning they will disappear whenever the server is closed.

From what you mentioned, I assume you're getting the following error: "attempt to perform arithmetic on nil value". If non-persistent values are fine by you, all you have to do to fix the error above is slightly change your code to this:
Code:
Game.setStorageValue(PACC_STORAGE, (Game.getStorageValue(PACC_STORAGE) or 0) + 1)

On the other hand, if you need a way to save values in a persistent fashion, I can propose two other solutions to achieve that: create a table on your database and use sql queries, or directly save the value on a file in your computer. Let me know if you need further help with this.
 
thanks, I totally forgot about the nil value :p

here's what I made:

when first player logins, doesnt matter what player it will set global storage to 0 if it's nill (there must be other ways but I'm short of ideas atm
Code:
if Game.getStorageValue(GLOBALSTORAGE_SCROLLS_USED) == nil then
        Game.setStorageValue(GLOBALSTORAGE_SCROLLS_USED, 0)
    end

and in script.lua

Code:
Game.setStorageValue(GLOBALSTORAGE_SCROLLS_USED, (Game.getStorageValue(GLOBALSTORAGE_SCROLLS_USED)) + 1)
 
Back
Top