" '}' expected near '=' " error appearing in a line that otherwise appears perfect - lua

When I attempt to run my script, I get an error returning on a variable assignment. I've re-checked my syntax many times and it doesn't seem to be a mistake I made there--I even had somebody else look at it just in case. However, the error that returns continuously points me to the syntax, and I can't seem to find a solution to this problem.
Here is the whole troublesome function:
function registerquestlines()
if player["testline"] == nil then
player["testline"] = {"prog" = {true,false,false}, "quests" = {"testline1", "testline2", "testline3"}, "prog#" = 1}
end
end
Again, the error I get is: '}' expected near '=' on the line in which I assign values to player["testline"].

A table initializer uses either an unquoted name or a bracketed expression, not a quoted name.
{prog = {true,false,false}}
{["prog"] = {true,false,false}}

Related

roblox LUA Expected 'end' (to close 'than' at line 3), got '='

function teleportTo(placeCFrame)
local plyr = game.Players.LocalPlayer;
if plyr.Character then
return plyr.Character.HumanoidRootPart.CFrame = placeCFrame;
end
end
teleportTo(game:GetService("Workspace").game:GetService("Workspace").Zeppelin.FuelTank1.Tank.CFrame)
my code is here, idk much about coding thanks for helping
and if you told me how to make the player teleport to a moving object it would be so super
The error is telling you what is going on.
When the code was being interpreted line by line, it expected the next symbol to be end, but instead it got =.
That means that something about how you're using the equals sign is incorrect. So when we look at the line :
return plyr.Character.HumanoidRootPart.CFrame = placeCFrame
You cannot assign a value on the same line as a return command. return is used to pipe a value out of a function so it can be used where the function was called.
But I'm pretty sure that isn't what you intended, you just want to set a player's position. So to fix your issue, remove the return.
if plyr.Character then
plyr.Character.HumanoidRootPart.CFrame = placeCFrame
end
The reason you are getting an error is because = is usually defined as setting a value, and no code can be executed after a return or it will error
If you wanted to, you could add return after all the code is done executing

how to fix Players.louie43pro.PlayerGui.admin.Frame.LocalScript:10: Expected identifier when parsing expression, got ')' error roblox studio?

I have a problem in Roblox studio. There's an error when im trying to make an admin command script using local script.
The error is
Players.louie43pro.PlayerGui.admin.Frame.LocalScript:10: Expected
identifier when parsing expression, got ')'
I have tried so many things to fix this error.
please help.
This is the script that i have
local rs = game:GetService("ReplicatedStorage")
local commandEvent = rs:WaitForChild("CommandEvent")
local frame = script.Parent
local enter = frame.Enter
local box = frame.CommandBox
--takes command and splits it up
local function get_command()
local command = ()
for word in string.gmatch(box.Text, "\S+") do
table.insert(command, word)
end
local action = command[1]
local person = command[2]
print(action)
print(person)
commandEvent:FireServer(action, person)
box.Text = " "
end
enter.MouseButton1Click:Connect(get_command)
Can anybody help me with my problem?
please..
local command = () is not valid Lua syntax.
() is the call operator. You want to create a table value so use the table constructor {}
local command = {}
Or maybe you forgot a function name? You could also do something like this
local command = getMeSomeTable()
Then the call operator would make sense. That function should return a table of course.
As soon as you have fixed this error you'll face another error for using an invalid escape sequence. Replace \S with %S to match a non-whitespace character.
In case you do not find 2 matches you'll run into the next error. So you should check if command actually has two elements at keys 1 and 2 befor you index them.
So maybe add something like
if action and person then command:FireServer(action, person) end

regular expression for removing empty lines produces wrong results

Can someone help me solve the problem I'm having with a regular expression? I have a file containing the following code:
I'm using a visit to find matches and replace them so that I can remove the empty lines. The result is, however, not what I'm expecting. The code is as follows:
str content = readFile(location);
// Remove empty lines
content = visit (content) {
case /^[ \t\f\v]*?$(?:\r?\n)*/sm => ""
}
This regular expression also removes non empty lines resulting in an output equal to:
Can someone explain what I'm doing wrong with the regular expression as well as the one shown below? I can't seem to figure out why it's not working.
str content = readFile(location);
// Remove empty lines
content = visit (content) {
case /^\s+^/m => ""
}
Kind regards,
Bob
I think the big issue here is that in the context of visit, the ^ anchor does not mean what you think it does. See this example:
rascal>visit ("aaa") { case /^a/ : println("yes!"); }
yes!
yes!
yes!
visit matches the regex at every postfix of the string, so the ^ is relative for every postfix.
first it starts at "aaa", then at "aa" and then at "a".
In your example visit, what will happen is that empty postfixes of lines will also match your regex, and substitute those by empty strings. I think an additional effect is that the carriage return is not eaten up eagerly.
To fix this, simply not use a visit but a for loop or while, with a := match as the condition.

Rails if statement using include? method giving either syntax or string literal error

In my RoR app, I am trying to create a method that will look at a text field (body) and post a message to slack if a UK mobile phone number has been shared. I am testing for the UK mobile phone number by searching for 07 or '+447' appearing anywhere in the body text.
def contact_details_shared
if self.body.include? '07' || self.body.include? '+447'
slack_post(self)
end
end
This gives the following error when I try to launch the app in localhost (e.g. rails s):
syntax error, unexpected tSTRING_BEG, expecting keyword_then or ';' or '\n'
But I can't see any syntax issues here.
So I also tried the following
def contact_details_shared
if ( self.body.include? '07' || self.body.include? '+447' )
slack_post(self)
end
end
This gives the following error when I try to launch the app in localhost (e.g. rails s):
warning: string literal in condition
I was surprised by this because my code should be returning a boolean for each OR condition (not a string).
So... two questions:
1) How can I get the code to work?
2) I imagine there are solutions that are altogether more elegant than mine. Suggestions very welcome! Any ideas?
Try:
if self.body.include?('07') || self.body.include?('+447')
I suspect ruby needs the explicit identification of the arguments (i.e., '07' and '+447') provided by the use of parentheses.
See this magic:
Ex: "hello07".include? '07'
return true
when you use
"hello07".include? '+441'
returns false
"hello07".include? '07' || "hello07".include? '+441'
SyntaxError: (irb):39: syntax error, unexpected tSTRING_BEG, expecting end-of-input
"hello07".include? '07' || "hello07".include? "+441"
^
if you use "or" instead of ||
"hello07".include?'07' or "hello07".include?'+447'
returns true
if you want to work your code, you can use
if self.body.include?('07') or self.body.include?('+447')
the solution is use "or" instead of "||"
if you want use the "||" use this syntax
if (self.body.include?'07') || (self.body.include?'+447')

Embedding mRuby: retrieving mrb_parser_message after parse error

I'm trying to embed mRuby in a Max MSP object. One of the first things I want to setup is error logging in the Max IDE console window. To that effect, after I parse the code ( stored in a C string ) with mrb_parse_string, I expect errors to be available in the parser's error_buffer array, but the structures in this array are always empty ( lineno and column set to 0 and message set to NULL ) even when there is an error.
Is there a special way to set up the parser before parsing the code so it fills its error_buffer array properly in case an error occurs ? I've looked into the mirb source, but it doesn't look like it. I'm lost. Here is the code I'm using, taken from a small C program I'm using as test:
mrb_state *mrb;
char *code;
struct mrb_parser_state *parser;
parser = mrb_parse_string(mrb, code, mrbc_context_new(mrb));
if (parser->nerr > 0) {
for(i = 0; i < parser->nerr; i++) {
printf("line %d:%d: %s\n", parser->error_buffer[i].lineno,
parser->error_buffer[i].column,
parser->error_buffer[i].message);
}
return -1;
}
When passed the following faulty ruby code:
[1,1,1]]
the previous code outputs :
line 1:8: syntax error, unexpected ']', expecting $end
line 0:0: (null)
I don't know where the first line comes from, since I compiled mRuby with MRB_DISABLE_STDIO defined and as line 14 and following in mrbconf.md suggests, but it is accurate.
The second line is the actual output from my code and shows that the returned mrb_parser_state structure's error_buffer is empty, which is surprising since the parser did see an error.
Sorry totally misunderstood your question.
So you want to:
capture script's syntax errors instead of printing.
make MRB_DISABLE_STDIO work.
For 1st issue
struct mrb_parser_state *parser;
parser = mrb_parse_string(mrb, code, mrbc_context_new(mrb));
should be replaced with:
struct mrbc_context *cxt;
struct mrb_parser_state *parser;
cxt = mrbc_context_new(mrb);
cxt->capture_errors = TRUE;
parser = mrb_parse_string(mrb, code, cxt);
like what mirb does.
For 2nd issue I don't know your build_config.rb so I can't say much about it.
Some notes to make things accurate:
MRB_DISABLE_STDIO is a compile flag for building mruby so you need to pass it in build_config.rb like:
cc.defines << %w(MRB_DISABLE_STDIO)
(see build_config_ArduinoDue.rb)
line 1:8: syntax error, unexpected ']', expecting $end
is the parsing error of mruby parser([1,1,1]] must be [1,1,1]).
And 1:8 means 8th column of 1st line (which points to unnecessary ]) so it seems like your C code is working correctly to me.
(For a reference your code's compilation error in CRuby:
https://wandbox.org/permlink/KRIlW2956TnS6puD )
prog.rb:1: syntax error, unexpected ']', expecting end-of-input
[1,1,1]]
^

Resources