I'm trying to read strings on separate lines/space as title says.
I have a row on phpmyadmin which is:
I have a made a function to get the list value on Lua and the next step would be to read every name separately and thats what i can't figure it out.
Its possible to read every line separately and then add them to an array?
As for example
local names = {Noba, Detalle}
Solved:
local names = {}
for _, name in ipairs(getList():explode("\n"))
table.insert(names, name)
end
Related
I am working on a game in Roblox and need a little help finding objects with attribute values. It is a tycoon for anyone here familiar with Roblox. I would like to know how you can find all instances with say the attribute Unlock_ID: 1, and then when you press the corresponding button, it will unlock it, or make it show up on the screen. I know how to make the objects unlock, I just don't know how to get all the objects with that attribute.
To put it more simply:
I want to find all the objects/instances inside a section with a specific attribute and a specific value and put them inside a table.
I hope this makes sense.
You can use a for i,v in ipairs loops along with the Folder:GetChildren() as your iteration directory. Then you can insert the instance (using table.insert(table,element) into a table if their part:GetAttribute('Unlock_ID') is equal to 1. To achieve this, simply do the following:
local partsWithAttribute = {}
local folder = workspace.Folder -- change this to whatever path you want to iterate through
for i,part in ipairs(folder:GetChildren()) do
if part:GetAttribute('Unlock_ID') == 1 then
table.insert(partsWithAttribute,part)
end
end
I have a zap that gets a block of text. Within that block of text they are about 30 variables that I need to replace e.g.{{variable1}}, {{variable2}}, {{variable3}} etc.
I need to replace each of these variables with a different string that I get in another step of the zap.
Zapier has a tool called find and replace text which works well; however it only works for 1 string at a time so this would mean I would need to do this 30 times.
Is there a way to complete this is one or two steps. Is it possible to use Code by Zapier (either Python or JS) to achieve this?
Yep! This can be done very easily using a code step in Python:
You'll pass any data into the Code step in the input_data dict. I'm not sure how it's coming in or formatted, but hopefully you can build a dict out of it. I'll make one up in this example.
keys = input_data['keys'] # something like "{{a}},{{b}},{{c}}"
values = input_data['values'] # something like "1,2,3"
replacers = {k:v for k,v in zip(keys.split(','), values.split(','))} # makes a mapping like {"{{a}}": "1", ...}
str_to_replace = input_data['string_to_repalace']
for k, v in replacers.items():
str_to_replace = str_to_replace.replace(k, v)
return {'result': str_to_replace}
How exactly this fits your use case depends on how your variables and stuff come in, but it should get you most of the way there.
So I'm trying to read a file, written with the format of a table:
({loop=true, test=1})
So basicly I want to read this data with this function:
function readAll(file)
local f = assert(io.open(file, "rb"))
local content = f:read("*all")
f:close()
return content
end
after I got the content of the file I use table.insert to store my data in an existing table..
but it seems like it stores my data as a string in the table, so if I try to get the data like this:
print(tablename.loop)
it returns nil, cause it hasn't made the table as I wanted it, it just pasted it as a string.
if I unpack the table I get the exact same thing as the code field at the top. A string.
So I try to insert it in the table, as valid variables, that I can read then easily with tablename.loop etc.
Sorry for my probably bad english.. I hope someone can help me.
thanks #Egor Skriptunoff. this is the solution I was looking for <3
since he only made a comment, I'll write his solution down again:
tablename = assert((loadstring or load)("return "..readAll(file)))(); print(tablename.loop)
everyone have a nice day!
I want to make a program that chooses a random monster from a list, give the user a list of usable weapons, and allows them to choose which weapon to use. I want to use external files to store data for the weapons instead of adding the tables in the Lua file itself. I have tried using Lua files to store the data as a table.
I have a file called sword.lua in the same folder as the program I want to access it's information. It contains
sword = {'sword', '10', '1', '100'}
I am trying to access the information using
wep = io.open("sword.lua", "r")
print(wep:read("*a"))
print(wep[1])
The first print returns all of the text in the file which is
"sword = {'sword', '10', '1', '100'}"
and the second is supposed to return the first item in the table. Every time I do this, I get a nil value from the second print. The file is being read, as indicated by the first print listing the text, but how do I make it read the file as a table that I can use in my program.
To load a table from a file use the require function. For example, save
return { 'sword', '10', '1', '100' }
as sword.lua. Why do I just use return instead of assigning to a variable? It's because that is much more flexible. If I assign the table to the variable sword inside the file, I'm sort of locked into that naming convention and furthermore I pollute the global namespace, making name collisions more likely.
With the above solution I can also assign to a local variable, like so
local sword = require("sword")
print(table.concat(sword,", "))
Another advantage is that calls to require are cached, i.e. even if you require("sword") many times, you only pay the cost for loading once. But keep in mind that because of caching you always get a handle to the same table, i.e. if you alter the table returned from require("sword"), these modifications will be shared by all instances.
Example on Wandbox
I'm developing a sketchup plugin with ruby, I have coded the parsing process succesfully and I got the cpoints from csv file to sketchup. The csv file also contains a description within coordinates of every point like : ["15461.545", "845152.56", "5464.59", "tower1"].
I want to get the tower1 as a text associated to every point.
How can I do that ?
PS : You don't need to get the tower1 from the array, i've already done that. I have it now in an independant variable like :
desc_array = ["tower1", "beacon48", "anna55", ...]
Please help me
I did that by
##todraw_su.each do |todraw|
##desc_array.each do |desc|
#model.entities.add_text desc, todraw
end
end
But I found a problem with each statement, it loops for every todraw in desc
If you know how I can do it, answer on this question Each statement inside another each malfunctions?