When I run the code it tells me there's an error which is ')' expected near '=':
function restartLvl()
for i = 1, #balloonTexts do
display.remove(balloonTexts[i])
print ("restart level")
end
score.text = '0'
ballRemain.text = '3'
balloonText = {}
createBalloons(1, 3)
if (askUser.isVisible = true) then --this is the line where the error occured
askUser.isVisible = false
end
if (yesBtn.isVisible = true) then
yesBtn.isVisible = false
end
if (noBtn.isVisible = true) then
noBtn.isVisible = false
end
end
I don't know how it is still missing a ')', because I closed all the brackets.
= is the assignment operator, == is the operator to test equality. Change it to:
if (askUser.isVisible == true) then
askUser.isVisible = false
end
And all the others as well. The brackets () can be ommited for simplicity:
if askUser.isVisible == true then
askUser.isVisible = false
end
If the value is a boolean, you can also do this because all values that are not nil or false are treated as true.
if askUser.isVisible then
askUser.isVisible = false
end
This is not related to your answer but
I recommend you to use lua glider IDE because this type error can be detect well by using this IDE.
Related
for i, v in pairs(Buttons:GetChildren()) do
local NewItem = BoughtItems:FindFirstChild(v.Item.value)
if NewItem ~= nil then
Items[NewItem.Name] = NewItem:Clone()
NewItem:Destroy()
else
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillBoardGui.Frame.Visible = false
end
if v:FindFirstChild("Dependency") then
coroutine.resume(coroutine.create(function(
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillBoardGui.Frame.Visible = false
if BoughtItems:WaitForChild(v.Dependency.Value, 100000)then
v.ButtonPart.Transparency = 0
v.ButtonPart.CanCollide = true
v.ButtonPart.BillBoardGui.Frame.Visible = true
end
end))
end
v.ButtonPart.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid")then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Values.OwnerValue.Value == Player then
if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
if Player:WaitForChild("leaderstats").Cash.Value >= v.Price.Value then
Player.leaderstats.Cash.Value -= v.Price.Value
Items[v.Item.Value].Parent = BoughtItems
v:Destroy()
end
end
end
end
end)
end
how do i fix this the header is the problem i dont knw what it means so is there a fix to it for my tycoon if anyone knows pls comment (heres some random stuff since my post is mostly code) A brief Introduction to Copypasta. Copypasta means to copy a text or a part of the text from an existing manuscript and inclusion of that very text in an under-process manuscript by pasting. At present, the societies are going to be expanded with an enormous pattern.
Parenthesis always come in pairs. The error message already strongly suggests that you are missing a closing parenthesis for an opening one in line 38.
1 2 3
coroutine.resume(coroutine.create(function(
v.ButtonPart.Transparency = 1
v.ButtonPart.CanCollide = false
v.ButtonPart.BillBoardGui.Frame.Visible = false
if BoughtItems:WaitForChild(v.Dependency.Value, 100000)then
v.ButtonPart.Transparency = 0
v.ButtonPart.CanCollide = true
v.ButtonPart.BillBoardGui.Frame.Visible = true
end
end)) <--- one is missing
1 2
Use a text editor that autocompletes pairs or even better one that hightlights pairs in matching colors to avoid errors like this.
Hello when i start the server and want to start doing illegal jobs this shows up
brx-drugs/client/client.lua:50: 'then' expected near '='
and here is also a piece of the code
Citizen.CreateThread(function()
while true do
Citizen.Wait(1000)
local pedCoords = GetEntityCoords(GetPlayerPed(-1))
local dst = #(Config.StartLocation - pedCoords)
if dst < 200 and jobSpawned = false then
TriggerEvent ('brx-drugs:spawnJobPed',Config.StartLocation, 217.980
jobSpawned = true
refreshJobPed = true
end
if dst>= 201 then
if DoesEntityExist(jobPed) then
DeletePed(jobPed)
end
JobSpawned = false
end
end
end)
i dont think the problem is with the config file and i cant get around it since im a new dev
Missing '=' in
if dst < 200 and jobSpawned = false then
jobSpawned = false
Change to
jobSpawned == false
Hi I am a user on Roblox and I am trying to script a light switch that turns off 4 lights and I am having a error (it's in the title)
There are 2 blocks being used, the Off4 and On4 switch.
My code is
function OnClicked()
if (workspace.LivingRoomLight.SpotLight.Enabled == true) and (workspace.LivingRoomLight2.SpotLight.Enabled == true) and (workspace.LivingRoomLight3.SpotLight.Enabled == true) and (workspace.LivingRoomLight4.SpotLight.Enabled == true) then
(workspace.LivingRoomLight.SpotLight.Enabled = false) and (workspace.LivingRoomLight2.SpotLight.Enabled == false) and (workspace.LivingRoomLight3.SpotLight.Enabled == false) and (workspace.LivingRoomLight3.SpotLight.Enabled == false)
script.Parent.Transparency = 1
workspace.Off4.Transparency = 0
end
end
script.Parent.ClickDetector.MouseClick:connect(OnClicked)
The other scripts (that work) I use in the ones that use only one light is
function OnClicked()
if (workspace.Hallwaylight.SpotLight.Enabled == true) then
workspace.Hallwaylight.SpotLight.Enabled = false
script.Parent.Transparency = 1
workspace.Off.Transparency = 0
end
end
script.Parent.ClickDetector.MouseClick:connect(OnClicked)
Note: I am only using the on scripts because that's the only one I edited for the one with the error. The error in the on script is the first = at column 3 and when I use '==' instead of '=' then the whole line becomes a error
Try this:
if (workspace.LivingRoomLight.SpotLight.Enabled == true) and (workspace.LivingRoomLight2.SpotLight.Enabled == true) and (workspace.LivingRoomLight3.SpotLight.Enabled == true) and (workspace.LivingRoomLight4.SpotLight.Enabled == true) then
workspace.LivingRoomLight.SpotLight.Enabled = false
workspace.LivingRoomLight2.SpotLight.Enabled = false
workspace.LivingRoomLight3.SpotLight.Enabled = false
workspace.LivingRoomLight4.SpotLight.Enabled = false
...
Some pointers:
x == y means “does x equal y?”. It’s a condition (either true or false).
x = y means “set x to y”. It’s a statement (a command to your program to modify the value of x).
and is an operator that expects conditions to its left and right.
Your program is of the form
if (these four values are true) then
set each of them to false
end
so you need and and == on the first line, but they don’t make sense inside the if — you need four simple statements using =, there.
You don’t really need == though. Comparing boolean values (like workspace.LivingRoomLight.SpotLight.Enabled, which are already true or false) to true is a bit silly: instead of if x == true then ... end it’s nicer to just write if x then ... end.
How do I do something like this?
if params[:property] == nil
#item.property = true
else
#item.property = false
Always forget the proper syntax to write it in one line.
In PHP it would be like this:
#item.property=(params[:property]==nil)true:false
Is it the same in rails?
use the ternary operator:
#item.property = params[:property] ? true : false
or force a boolean conversion ("not not" operation) :
#item.property = !!params[:property]
note : in ruby, it is a common idiom not to use true booleans, as any object other than false or nil evaluates to true.
m_x answer is perfect but you may be interested to know other ways to do it, which may look better in other circumstances:
if params[:property] == nil then #item.property = true else #item.property = false end
or
#item.property = if params[:property] == nil then true else false end
Is it possible to do this in ruby?
variablename = true
if variablename
puts "yes!"
end
Instead of this
variablename = true
if variablename == true
puts "yes!"
end
Edit:
also considering having:
variablename = 0 #which caused my problem
I can't get that to work. Is such a style of saying if possible? I'm learning ruby now, and it is possible in PHP but im not sure how to do it right in ruby
sure, it's possible
everything except nil and false is treated as true in ruby. Meaning:
var = 0
if var
# true!
end
var = ''
if var
# true!
end
var = nil
if var
# false
end
xdazz and Vlad are correct with their answers, so you would need to catch 0 separately:
variable = false if variable.zero? # if you need 0 to be false
puts "yes!" if variable # now nil, false & 0 will be considered false
It's possible at all. In ruby, only nil and false is considered as false, any other value is true.