simple help with if statement and functions

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By siten0308

Hey everyone,

cant believe i need help with a simple if statement, so trying hard to go from C# to GDScript, and i do know python ,however the indenting is tough, the code is below and not working, its saying on the ChangeDirection(“Right”) is saying “Unindent does not match any outer indentation level.”

WEELL IT SHOULD!!! its only right under the dang IF statement! ugh python was hard and for some reason C# was easy to pick up… dont know why dont ask… but trying to convert from unity to Godot… but maybe i should stay with unity… and NO!!! i will not go with godot C#, i tried and believe me… so many things wrong with godot documentation that i presened on this forum and no reply backs, i also asked questions, no reply backs… so i am hoping someone can figure this out to give some hope in me continuing learning Godot or maybe not… below is the code:

extends KinematicBody2D

export (int) var run_speed = 300
export (int) var jump_speed = -600
export (int) var gravity = 1200

var velocity = Vector2()
var jumping = false
var Direction = “Left”

func ChangeDirection(var Direction):
if Direction == “Left”:
get_node( “Sprite” ).set_flip_h( false )
Direction = “Right”
elif Direction == “Right”:
get_node( “Sprite” ).set_flip_h( true )
Direction = “Left”

func get_input():
velocity.x = 0
var right = Input.is_action_pressed(‘ui_right’)
var left = Input.is_action_pressed(‘ui_left’)
var jump = Input.is_action_just_pressed(‘ui_select’)

if jump and is_on_floor():
    jumping = true
    velocity.y = jump_speed
if right:
    velocity.x += run_speed
	ChangeDirection("Right")
if left:
    velocity.x -= run_speed
	ChangeDirection("Left")

func _physics_process(delta):
get_input()
velocity.y += gravity * delta
if jumping and is_on_floor():
jumping = false
velocity = move_and_slide(velocity, Vector2(0, -1))

Hey SIsilicon

thank you for answering, so its seems that worked, well what i did was backspace, then hit space bar 8 times instead of using the tab twice on the new line… not sure why space works more than tab but thanks.

siten0308 | 2018-12-31 01:52

:bust_in_silhouette: Reply From: SIsilicon

Indentation may not matter in C#, but it does in GDscript.

if condition:
    statement # this line is one tab / four spaces ahead of the if.

Hello, thank you for the answer, i sorta knew that, if you looked at my code:

if Direction == "Left":
   getnode( "Sprite" ).setfliph( false )

it is indentation, its just i realize i have to also indent for it to come out as code, but also i am familiar with python.

the other thing I realize is, the method.properties of some of the objects dont exist on kinematicbody2d, and only for sprites i guess… lot to learn… but then again, maybe should not put myself through this when i know some other engines. thanks for your assistance though.

siten0308 | 2018-12-31 04:58