0 votes

Hi guys, still very new to GDScripting and this has me stumped. I have been working on the step by step pong tutorial; (http://docs.godotengine.org/en/2.1/learning/step_by_step/simple_2d_game.html)
I am hitting some dead ends. Can anyone help me where I'm going wrong, code to follow.

extends Node2D

var screensize
var pad
size
const PADSPEED = 150
var ball
speed = 80
var ball_direction = Vector2(-1, 0)

func ready():
screen
size = getviewportrect().size
padsize = getnode("left").gettexture().getsize()
set_process(true)

func process(delta):
var ball
pos = getnode("ball").getpos()
var leftrect = Rect2( getnode("left").getpos() - padsize0.5, padsize )
var right
rect = Rect2( getnode("right").getpos() - pad_size
0.5, pad_size )

# Flip when touching roof or floor
if ((ball_pos.y < 0 and direction.y < 0) or (ball_pos.y > screen_size.y and direction.y > 0)):
    direction.y = -direction.y

if (( left_rect.has_point(ball_pos) and ball_direction.x < 0 ) or ( right_rect.has_point(ball_pos) and ball_direction.x > 0)):
    ball_direction.x = -ball_direction.x
    ball_speed *= 1.1
    ball_direction.y  = randf() * 2.0 -1
    ball_direction = ball_direction.normalized()

if (ball_pos.x < 0 or ball_pos.x > screen_size.x):
    ball_pos = screen_size * 0.5 
    ball_speed = 80
    ball_direction = Vector2(-1,0)

get_node("ball").set_pos(ball_pos)


var left_pos = get_node("left").get_pos()
if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")):
    left_pos.y += - PAD_SPEED * delta

if (left_pos.y < screen_size.y and Input.is_action_pressed("left_move_down")):
    left_pos.y += PAD_SPEED * delta

get_node("left").set_pos(left_pos)

var right_pos = get_node("right").get_pos()
if ( right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
    right_pos.y  += - PAD_SPEED * delta

if ( right_pos.y < screen_size.y and Input.is_action_pressed("right_move_down")):
    right_pos.y += PAD_SPEED * delta

get_node("right").set_pos(right_pos)
asked Jul 15 in Projects by anthony_svarcbergs (12 points)

A couple of comments:

1) This is a very old tutorial, based on Godot 2.1. Are you using Godot 2.1? If so why? If not, you should follow the much improved 3.1 docs version. Most people are using 3.1 these days, so it's going to be harder to find help.

2) You just pasted code but didn't include anything about what went wrong.

Yes using 3.1 but I just googled it and found that tutorial so I will look for a newer one.

Thanks for the tip on the What went wrong. my apologies,
this I copied from the errors dialogue box:
E 0:00:00:0280 Condition ' debugparseerrline >= 0 ' is true. returned: __null
modules/gdscript/gdscripteditor.cpp:330 @ debuggetstacklevel_instance()

What other info can I get to help you see my mistakes?

and thanks so much

Please log in or register to answer this question.

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.