:contains?

Eorzea Time
 
 
 
言語: JP EN FR DE
日本語版のFFXIVPRO利用したい場合は、上記の"JP"を設定して、又はjp.ffxivpro.comを直接に利用してもいいです
users online
フォーラム » Windower » General » :contains?
:contains?
 Lakshmi.Elidyr
Offline
サーバ: Lakshmi
Game: FFXI
user: elii
Posts: 911
By Lakshmi.Elidyr 2017-05-15 20:37:45  
Does this not work anymore?

Edit: I guess I could be more specific...
Code
if table:contains(name) then ...
 Fenrir.Caiir
VIP
Offline
サーバ: Fenrir
Game: FFXI
user: Minjo
Posts: 199
By Fenrir.Caiir 2017-05-15 21:09:05  
{}:contains() is not valid because a table has no default contains method. T{}, S{}, L{}, etc are wrappers to tables that have many methods available to them, including contains, thanks to libraries. For general purposes, S{} is the most efficient at this particular operation, though just comparing equality (==) is faster (much uglier, though).
 Lakshmi.Elidyr
Offline
サーバ: Lakshmi
Game: FFXI
user: elii
Posts: 911
By Lakshmi.Elidyr 2017-05-15 23:03:48  
Write, it was just an example. I have this:
Code
table = S{buncha strings}

if table:contains("random string name") then
**do stuff** in case that wasn't assumed.
end



Not working at all like it was. I had to change a bunch of stuff I already had written a while back because it wasn't working.

I just ended up making my own function anyway.
Code
function contains(t, v)
    
    for i, val in ipairs(t) do
        
        if val == v then
            return true
            
        end
        
    end
    return false
    
end
 Ragnarok.Kenshi
Offline
サーバ: Ragnarok
Game: FFXI
user: KenshiDRK
Posts: 123
By Ragnarok.Kenshi 2017-05-16 05:06:39  
You gotta call the tables library
Code
require 'tables'
table = S{buncha strings}
 
if table:contains("random string name") then
**do stuff** in case that wasn't assumed.
end
 Lakshmi.Elidyr
Offline
サーバ: Lakshmi
Game: FFXI
user: elii
Posts: 911
By Lakshmi.Elidyr 2017-05-16 08:18:20  
Ragnarok.Kenshi said: »
You gotta call the tables library
Code
require 'tables'
table = S{buncha strings}
 
if table:contains("random string name") then
**do stuff** in case that wasn't assumed.
end

I think Gearswap has it instanced already, maybe the scope of things I'm unable to use?
 Lakshmi.Elidyr
Offline
サーバ: Lakshmi
Game: FFXI
user: elii
Posts: 911
By Lakshmi.Elidyr 2017-05-16 10:30:11  
Recalled inside, seems to be working. I figured once it was instanced inside Gearswap I should of had access inside my file.
 Leviathan.Vow
Offline
サーバ: Leviathan
Game: FFXI
user: woVow
Posts: 125
By Leviathan.Vow 2017-05-17 08:44:52  
You should not have to call require in your file to access the tables or sets libraries. You don't have to track down the error if you don't want to, but -- somewhere in your code -- you've written something that modifies your user environment in a way that is not immediately clear to me.
 Lakshmi.Byrth
VIP
Offline
サーバ: Lakshmi
Game: FFXI
user: Byrthnoth
Posts: 6137
By Lakshmi.Byrth 2017-05-17 08:46:26  
Don't use common terms like "table" for your global variables. Something like that is almost certainly causing your problem.
 Lakshmi.Elidyr
Offline
サーバ: Lakshmi
Game: FFXI
user: elii
Posts: 911
By Lakshmi.Elidyr 2017-05-17 10:15:53  
Lakshmi.Byrth said: »
Don't use common terms like "table" for your global variables. Something like that is almost certainly causing your problem.

I was only using for examples sake. I completely understand what you mean. I just put a require in my library fixed everything. Thank you though Byrth.
 Lakshmi.Elidyr
Offline
サーバ: Lakshmi
Game: FFXI
user: elii
Posts: 911
By Lakshmi.Elidyr 2017-05-17 10:29:20  
Ill post code just for full understanding sake. I am rebuilding everything from scratch though so a lot of my stuff if missing, but still functions at this current moment. I started this because it just fit my play style, and everything works the way I want it to. May not be the best, but that's okay.

Blue Mage LUA Example:

Main File

Job Library

Gear File


The event in question was a function inside the include file in the job library. Specifically this bit here:
Code
-- ** Multibox Settings.
    r = require 'resources'
        require('/buddypal/bpcore.lua')
         
    --bpLoadLibrary()       -- Load Buddypal Library
    --loadBLUSettings()     -- Load job specific features for multiboxing.