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

my script doubt TFS 1,2

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
151
Reaction score
9
I have this script part on my quests.lua

Lua:
if player:getStorageValue(700,1) or player:getStorageValue(701,1) or player:getStorageValue(702,1) or player:getStorageValue(703,1) or player:getStorageValue(704,1) then
        player:setStorageValue(805, 1)
    end

my doubt Is there any simpler way to make this part? I'm using a lot of 'or'
 
Solution
I have this script part on my quests.lua

Lua:
if player:getStorageValue(700,1) or player:getStorageValue(701,1) or player:getStorageValue(702,1) or player:getStorageValue(703,1) or player:getStorageValue(704,1) then
        player:setStorageValue(805, 1)
    end

my doubt Is there any simpler way to make this part? I'm using a lot of 'or'

first way
Lua:
for i = 700, 704 do
    if player:getStorageValue(i) == 1 then
        player:setStorageValue(805, 1)
        break
    end
end

second way (you can put as many storage as you want into the table in any order)
Lua:
local storages = {700, 701, 702, 703, 704}
for i = 1, #storages do
    if player:getStorageValue(storages[i]) == 1 then
        player:setStorageValue(805, 1)...
I have this script part on my quests.lua

Lua:
if player:getStorageValue(700,1) or player:getStorageValue(701,1) or player:getStorageValue(702,1) or player:getStorageValue(703,1) or player:getStorageValue(704,1) then
        player:setStorageValue(805, 1)
    end

my doubt Is there any simpler way to make this part? I'm using a lot of 'or'

first way
Lua:
for i = 700, 704 do
    if player:getStorageValue(i) == 1 then
        player:setStorageValue(805, 1)
        break
    end
end

second way (you can put as many storage as you want into the table in any order)
Lua:
local storages = {700, 701, 702, 703, 704}
for i = 1, #storages do
    if player:getStorageValue(storages[i]) == 1 then
        player:setStorageValue(805, 1)
        break
    end
end
 
Last edited:
Solution
very nice ! i liked this
Lua:
local storages = {700, 701, 702, 703, 704}
for i = 1, #storages do
    if player:getStorageValue(storages[i]) == 1 then
        player:setStorageValue(805, 1)
        break
    end
end

other question, if i will do the same with other code but same file.lua, like this,

example:
Lua:
local storages = {700, 701, 702, 703, 704}
for i = 1, #storages do
    if player:getStorageValue(storages[i]) == 1 then
        player:setStorageValue(805, 1)
        break
    end
end
Lua:
local storages = {800, 801, 802, 803, 804}
for i = 1, #storages do
    if player:getStorageValue(storages[i]) == 1 then
        player:setStorageValue(905, 1)
        break
    end
end

where i can use elseif ? after break?
 
very nice ! i liked this
where i can use elseif ? after break?
depends what you need, break stop a for function, if player have a storage == 1 , the break will stop, and not need to check the other storages

exemple this code, if player have storage 801 == 1, the break will stop the FOR, and it will not check storage 803, 804, because it already found a storage 801 == 1
Lua:
local storages = {800, 801, 802, 803, 804}
for i = 1, #storages do
    if player:getStorageValue(storages[i]) == 1 then
        player:setStorageValue(905, 1)
        break
    end
 
Back
Top