Lua error in ground scripting in the first tutorial (SOLVED)

**local pieces = { “ground0”, “ground1”, “ground2”, “ground3”,
“ground4”, “ground5”, “ground6” } 1

function init(self) 2
self.speed = 6
end

function update(self, dt) 3
for i, p in ipairs(pieces) do 4
local pos = go.get_position§
if pos.x <= -228 then 5
pos.x = 1368 + (pos.x + 228)
end
pos.x = pos.x - self.speed
go.set_position(pos, p) 6
end
end**

get an error in line 2

Description Resource Path Location Type
unexpected symbol near '1’
ground.script /Getting Started Tutorial/content/main line 2 Problem

what am i doing wrong ?

sorry for the question but i am a noob

1 Like

You must remove the numbers at the end of the lines.

Try this:

local grounds = {"ground0", "ground1", "ground2", "ground3", "ground4", "ground5", "ground6"}

function init(self)
	self.speed = 6
end

function update(self, dt)
	for i, ground in ipairs(grounds) do
		local pos = go.get_position(ground)
		
		if pos.x <= -228 then
			pos.x = 1368 + (pos.x + 228)
		end
		
		pos.x = pos.x - self.speed
		go.set_position(pos, ground)
	end
end

I recommend you read this: https://www.lua.org/manual/5.3/

2 Likes

In the future, it’s better for your learning to write out the code rather than copy and pasting it.

3 Likes

I agree. You’d be surprised how much more you learn simply by typing in the code instead of copy-pasting it.

3 Likes

Thanks !
I ll get there in the end and learn lua but for the moment i want to get the hang of the editor first
I just copied the instruction in the tutorial which said to copy and paste it
BTW the tutorial needs to be corrected then as i see the 1 at the end of the line

this is the incriminating bit

Right-click the “main” folder in the Project Explorer and select New ▸ Script File. Name the new file "ground.script"
Double click the new file to bring up the Lua script editor.
Delete the default content of the file and copy the following Lua code into it, then save the file.
ground.script
local pieces = { “ground0”, “ground1”, “ground2”, “ground3”,
“ground4”, “ground5”, “ground6” } 1

1 Like

maybe the numbers at the side of the lua script should be commented with // so they do not generate code errors
seems you need to remove all the 1 - 6 numbers

i got there in the end

i wonder what i ll ask you next :slight_smile:

The numbers are there because they are annotations on the web page version of the source with text below explaining each part. When you copy and paste code that’s why they show up if there are any.

I’ll see if they can at least be commented out so you don’t have to manually remove them.

1 Like

Might be too much time to do but if the codeblocks had line numbers to the left you could bold the line numbers you want to highlight and then talk about them below.

CSS example

for a noob it s quite confusing , i d suggest either take them out or comment them ouit with // like in c#
i ve never done lua , and are a beginner in c# but i would have realized what was wrong with c#

alternatively the copy and paste bit in the instruction should be edited out or changed to warn of the numbers

thanks again to everybody !
i m sure i ll be back soon with more problems :slight_smile:

1 Like

Nitpicking here, but in Lua it’s – for a single line comment :slight_smile:

1 Like

In my opinion, I would rather just see a warning above the code block, that makes the reader pay attention to the annotation. The formatting of the numbers makes it reasonably obvious that they’re something special, and with an “Attention: Numbers formatet as … is related to the annotations below the code block”, there shouldn’t be any doubt left. Just by reading the code, line by line, one should notice the pattern.

As it stands now, one either catches the numbers and remove them, or get an error, forcing one to debug and by that increase one’s knowledge. And if people get stuck, we’re always here, ready to guide them as best we can. :slight_smile:

1 Like

I found a way to make these callouts not part of the selected text so they won’t be part of copy-paste anymore. It works fine in Safari and Chrome.

3 Likes

Still editing them? What I see on Windows Chrome Version 49.0.2623.112 m

Edit: doing a forced refresh fixes it

1 Like

Yeah, probably cached css.