'=' expected near var_y - syntax

I have this code:
function var_leafdrop(var_inc, var_restpos)
If var_y >= var_restpos then
var_y = var_restpos
else
var_y = var_y + var_inc
end
return var_y
end
I get error:
error 18: '=' expected near 'var_y'
18 being the line:
If var_y >= var_restpos then
I've tried:
Changing the variable name
Changing its declaration
Removing the if then block
Moving the entire function to the beginning of the script file
This is using the built in script editor for Watchmaker.
I can't see any error!? I just don't get it. Is this some dumb idiosyncrasy with Watchmaker...?

As mentioned in the comments, Lua is case sensitive.
So use if instead of If.

Related

`*': negative argument (ArgumentError) Ruby

I keep getting this negative argument error when running this code in the Codewars IDE. It runs fine in terminal but in Codewars it both passes the test and runs this error message simultaneously.
STDERR
main.rb:5:in `*': negative argument (ArgumentError)
from main.rb:5:in `maskify'
from main.rb:9:in `<main>'
The code is
def maskify(cc)
x = cc.to_s
y = "#" * (x.length - 4)
return y + x.slice(-4..-1)
end
I'm new to Ruby but I've not heard anywhere that it has a problem with negative numbers being used in .slice. Am I missing something here? Thanks.
You're not considering cases when cc is shorter than 4 symbols.
And expression "#" * (x.length - 4) raises the error because you can't multiply a string by a negative number.
Try to use Array#max method to handle this:
"#" * [x.length - 4, 0].max

Currently trying to script a game and I don't understand how to debug this section of coding

I'm following a youtube tutorial on scripting to create a game on roblox and whilst following it, "Status", the variable I use to identify a value decides to stop working (line39). My output box says the following:
21:16:36.197 - sword game.rbxl auto-recovery file was created
21:16:36.715 - ServerScriptService.MainScript:39: Expected ']' (to close '[' at line 37), got 'Status'
21:16:38.617 - ScriptNavigationHandler : No script currently available.
I haven't learned much about debugging code but if someone can shine some light on what is wrong that would greatly help me on my conquest to learn scripting during the fight against the invisible enemy.
-- Define varibles
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local Status = ReplicatedStorage:WaitForChild("Status")
local GameLength = 60
--Game loop
while true do
Status.Value = "Waiting for enoughplayers"
repeat wait(1) until game.Players.NumPlayers >=2
Status.Value = "Intermission"
wait(8)
local plrs = {}
for i, player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player) --Add each player into plrs table
end
end
wait(2)
local AvaliableMaps =MapsFolder:GetChildren()
local ChosenMap = AvaliableMaps[math.random(1,#AvailableMaps)
Status.Value = ChosenMap.Name "Chosen"
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = workspace
-- Teleport players to the map
local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
if not SpawnPoints then
print("SpawnPoints not found!")
end
local AvailableSpawnPoints = SpawnPoints:GetChildren()
for i, player in pairs(plrs) do
if player then
character = player.Character
if character then
-- Teleport them
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
table.remove(AvailableSpawnPoints,1)
-- Give Sword
local Sword = ServerStorage.Sword:Clone()
Sword.Parent = player.Backpack
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = player.Character
else
-- There is no character
if not player then
table.remove(plrs,i)
end
end
end
end
end
In
local ChosenMap = AvaliableMaps[math.random(1,#AvailableMaps)
you are missing the closing square bracket.
Night94 has pointed out the correct fix for your broken code, but since your question is about learning to debug, I'll try to help you understand your error messages.
21:16:36.715 - ServerScriptService.MainScript:39: Expected ']' (to close '[' at line 37), got 'Status'
Let's break this down piece by piece :
ServerScriptStorage.MainScript:39 this tells us where the file is, and on what line the error appeared.
So let's look at line 39 (through 41) you see :
local ChosenMap = AvaliableMaps[math.random(1,#AvailableMaps)
Status.Value = ChosenMap.Name "Chosen"
Next we have : Expected ']' (to close '[' at line 37), got 'Status'
This means that at some point, the code was expecting a square bracket to close the one that was opened at 37 : AvaliableMaps[, but instead it found the next line of code Status
So with these pieces of information, you should have all the pieces to understand what went wrong: A square bracket was opened, but never closed. It should go somewhere before the next line of code.
local ChosenMap = AvaliableMaps[math.random(1,#AvailableMaps)]

Visual Studio - Input string was not in a correct format

I have a part of my code here (file parser program) that gives me an error of: Input string was not in a correct format
For Each h1 As Char In PRIM_BIT.ToCharArray
rawbit = Convert.ToString(Convert.ToInt32(h1, 16), 2)
pribitval = pribitval & StrDup(4 - rawbit.Length, "0") & rawbit
Next
I tried to use int.TryParse, but it doesn't work. Is there a way to parse this?
Check the value of h1 when the error occurred.
h1 has to be a valid digit. Such as 0 ~ 9, a ~ f, A ~ F.
Also, h1 cannot be empty.
Edit:
If you want to bypass this and proceed, you can use Try...Catch... statement
For Each h1 As Char In PRIM_BIT.ToCharArray
Try
rawbit = Convert.ToString(Convert.ToInt32(h1, 16), 2)
pribitval = pribitval & StrDup(4 - rawbit.Length, "0") & rawbit
Catch ex As Exception
'Do something when error occurs. Or simply do nothing.
End Try
Next
I still recommend you to check what went wrong when the error occurred.

Expected parenthesis errors gfortran

I am trying to compile some fortran code using gfortran v.4.8.2.
When I compile, I get the following errors:
ant_driver.f90:185.72:
if (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns)
1
Error: Syntax error in IF-expression at (1)
ant_driver.f90:187.119:
ry%thck(ew,ns) = -rhoo/rhoi * (model%geometry%topg(ew,ns)- model%climate%eus(ew,
1
Error: Expected a right parenthesis in expression at (1)
ant_driver.f90:188.27:
endif
1
Error: Expecting END DO statement at (1)
ant_driver.f90:248.82:
odel%geometry%usrf(ew,ns) = - (model%geometry%topg(ew,ns)-model%climate%eus(ew,
1
Error: Expected a right parenthesis in expression at (1)
ant_driver.f90:260.107:
model%geometry%usrf(ew,ns) - (model%geometry%topg(ew,ns)-model%climate%eus(ew,
1
Error: Expected a right parenthesis in expression at (1)
ant_driver.f90:174.30:
call glide_set_eus(model,eus)
1
Error: Rank mismatch in argument 'inarray' at (1) (scalar and rank-2)
The errors relate to the following lines of code:
185-188:
if (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns) < 0 .and. model%geometry%thck(ew,ns) == 0 .and. &
mask(ew,ns) == 1) then
model%geometry%thck(ew,ns) = -rhoo/rhoi * (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns))
endif
248:
model%geometry%usrf(ew,ns) = - (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns)) * rhoo/rhoi &
+ (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns))
260:
model%geometry%thck(ew,ns) = model%geometry%usrf(ew,ns) - (model%geometry%topg(ew,ns)-model%climate%eus(ew,ns))
174:
call glide_set_eus(model,eus)
Any help much appreciated. Thank you for your time.
Your errors are due to line truncation. For fixed-form Fortran a line length of 72 characters is specified and for free-form Fortran it should be 132 characters. You source should be interpreted as free-form due to the .f90 extension but you can force free-form in gfortran with -ffree-form. You can also alter the maximum line lengths in fixed- and free-form source with the options -ffixed-line-length-n and -ffree-line-length-n respectively, where n is the number of characters and values of 0 or none mean unlimited line length.

Term to packet erlang. Constructing a binary

I have the following code:
term_to_packet(Term) ->
B = term_to_binary(Term),
A = byte_size(B),
<< 1:4/integer-unit:8, B:A/integer-unit:8 >>.
However, when I run:
term_to_packet("Hello").
I get an error:
exception error: bad argument in function term_to_packet line 20
where line 20 corresponds to the last line of the term_to_packet function.
I'm not quite sure what's throwing this error.
B is a binary, but in the binary construction on the last line you specify that it is an integer. This seems to work:
term_to_packet(Term) ->
B = term_to_binary(Term),
A = byte_size(B),
<< 1:4/integer-unit:8, B:A/binary-unit:8 >>.

Resources