my script doubt TFS 1,2

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
123
Best answers
0
Reaction score
6
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'
 

roriscrave

Intermediate OT User
Joined
Dec 7, 2011
Messages
628
Best answers
17
Reaction score
74
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:
OP
G

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
123
Best answers
0
Reaction score
6
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?
 

roriscrave

Intermediate OT User
Joined
Dec 7, 2011
Messages
628
Best answers
17
Reaction score
74
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
 
Top