0 votes
    if fmod((n/3),2): border = Color(1,1,1); road = Color(0.42,0.42,0.42)
    else: border = Color(0,0,0); road = Color(0.4,0.4,0.4)
    if (fmod((n/9),2)): border = Color(0,0,0); road = Color(0.2,0.2,0.2)
    else: border = Color(1,1,1); road = Color(0.8,0.8,0.8)

"Error parsing expression, misplaced: else"

the error happens with both else here. As a beginner, I'm not sure why. This code is mostly written by my friends but when I continued writing it myself I found this error.

Here is the whole section of the function:

func _draw():
pos += 200; if pos == 320000: pos = 0
while (pos >= num*seg): pos-= num*seg; while (pos < 0): pos += num*seg
var num_pos = 0; var start_point = pos/seg
var cam_h = 1500 + lines[start_point].y
var cutoff = height; var x=0; var dx=0;
skln_pos += lines[start_point].curve*2.0
skln_h = -lines[start_point].y*0.005
skyline.set_region_react(Rect2(skln_pos,skln_h,1920,320))
var dir = lines[start_point].curve
if dir >= 0.5: Car.rule = 3; Car.img.set_hidden(false)
if dir < 0.5 and dir > -0.5: Car.rule = 2; Car.img.set_hidden(false)
if dir <= -0.5: Car.rule =1; Car.img.set_hidden(false)
for n in range(start_point,start_point+300):
    if n>= num: num_pos = num*seg
    else: num_pos = 0
    var l = line(lines[fmod(n,num)],-x,cam_h,pos-num_pos)
    var p = lines[fmod(n-1,num)]
    x += dx; dx += l.curve
    if l.Y >= cutoff: continue
    cutoff = l.Y
    if fmod((n/3),2): border = Color(1,1,1); road = Color(0.42,0.42,0.42)
    else: border = Color(0,0,0); road = Color(0.4,0.4,0.4)
    if (fmod((n/9),2)): border = Color(0,0,0); road = Color(0.2,0.2,0.2)
    else: border = Color(1,1,1); road = Color(0.8,0.8,0.8)
    drawRoad(grass,0m p.Y, width, 0, l.Y, width)
    drawRoad(border,p.X, p.Y, p.W*1.2, l.X, l.Y, l.W*1.2)
    drawRoad(road,p.X, p.Y, p.W, l.X, l.Y, l.W)
    drawRoad(divid_line,p.X, p.Y, p.W*0.01, l.X, l.Y, l.W*0.01)
in Engine by (12 points)

1 Answer

+2 votes

Just guessing, but... I bet the parser is getting tripped up by the fact that you have 2 statements on the same line with the if. In your original code, this:

if fmod((n/3),2): border = Color(1,1,1); road = Color(0.42,0.42,0.42)
else: border = Color(0,0,0); road = Color(0.4,0.4,0.4)

Is likely seen exactly the same as this:

if fmod((n/3),2): border = Color(1,1,1)
road = Color(0.42,0.42,0.42)
else: border = Color(0,0,0); road = Color(0.4,0.4,0.4)

Which is obviously incorrect, and generates the same error as the first set of code.

Really, your code should be formatted as follows:

if fmod((n/3),2): 
    border = Color(1,1,1)
    road = Color(0.42,0.42,0.42)
else: 
    border = Color(0,0,0)
    road = Color(0.4,0.4,0.4)
by (12,282 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.