It looks like you're new here. If you want to get involved, click one of these buttons!
Hello,
I am taking up @Ignatz “learn codea” pdf guide.
I would like to know what exactly I am doing wrong.
The purpose of this code @Ignatz produced, was to demonstrate once the red line (aka: the arrow) hits a yellow floating ball, we get a score.
I did not paste his code, instead I typed it. I’m a beginner, so for me typing in the code allows it to sink in.
I compared our codes - and I cannot find what is causing the error on my side, but his code is working fine.
Please just let me know what I did wrong
(over explaining with examples that have nothing to do with this code - - will confuse me)
It’s been a couple years since I’ve been on this forum - and when I was on here, I was a beginner grappling with the concepts of variables.
Here is @Ignatz working code:
function setup()
balloonWidth=50
balloonHeight=60
balloonX=WIDTH/2
balloonY=0
balloonSpeed=1
arrowWidth=40
arrowStartX=50
arrowX=arrowStartX
arrowY=HEIGHT/2
arrowSpeed=3
score=0
end
function draw()
background(0)
pushStyle()
fill(255,255,0,150)
balloonY=balloonY+balloonSpeed
if balloonY-balloonHeight/2>HEIGHT
then balloonY=0
end
ellipse(balloonX,balloonY,balloonWidth,balloonHeight)
arrowX=arrowX+arrowSpeed
if arrowX>WIDTH
then arrowX=arrowStartX
end
if arrowX>balloonX-balloonWidth/2
and arrowX<=balloonX+balloonWidth/2
and arrowY>balloonY-balloonHeight/2
and arrowY<=balloonY+balloonHeight/2
then score=score+1
print("Hit!",score)
balloonY=0 arrowX=arrowStartX --reset balloon and arrow
end
stroke(245, 30, 55)
strokeWidth(5) line(arrowX,arrowY,arrowX+arrowWidth,arrowY) popStyle()
end
My code (what did I do wrong?) please POINT out the specific code line or code lines —Thank You
function setup()
balloonWidth=50
balloonHeight=60
balloonX=WIDTH/2 --sets (x axis) position to mid screen.
balloonY=0 --sets y axis position
balloonSpeed=1 --sets speed
--ARROWS
arrowWidth=40
arrowStartX=50 --where arrow starts from left
arrowX=arrowStartX --current x value of arrow
arrowY=HEIGHT/2 --later this will be touch
arrowSpeed=3
score=0
end
function draw()
background(4)
pushStyle()
fill(255,255,0,150)
--adjust vertical (y axis) position
balloonY=balloonY+balloonSpeed
--checks if ball at top of screen, restarts draw bottom if ball at top of screen
if balloonY-balloonHeight/2>HEIGHT
then balloonY=0
end
ellipse(balloonX,balloonY,balloonWidth,balloonHeight)
--ARROWS
arrowX=arrowX+arrowSpeed --similiar to balloon
if arrowX>WIDTH
then arrowX=arrowStartX
end
--Collision Detect
if arrowX>balloonX-balloonWidth/2
and arrowX<=balloonX+balloonWidth/2
and arrowY>balloonY-balloonHeight/2
and arrowY<=balloonY+balloonHeight/2
then score=score+1
print("Hit!",score)
balloonY=0 arrowX=arrowStart --reset balloon and arrow
end
--STROKE
stroke(239, 52, 57) --arrow color
strokeWidth(5) --pixels wide
line(arrowX,arrowY,arrowX+arrowWidth,arrowY) --draw arrow
popStyle()
end
Comments
In the third line of Collision Detect, you spelled ballonY wrong, it should be balloonY.
I’m going to jump out a window.

I combed though that code, in multitask view (photo app of the code on one side) Codea on the other for about 25 minutes, three times.
All this time, it was one letter - how comical, but I’m cool with it.
Thank you @dave1707
@tactfulgamer When you run the code and it stops because of an error, it shows you what the problem is. It says you have a nil value, gives you the line number of the error, and shows you the variable that’s has the problem. In this case it showed you ballonY. It won’t always be this easy though. Sometimes you’ll get an error, but it may be caused by something else. The more mistakes you make, the better you’ll get at finding them. So keep on coding and keep making mistakes.
Yes, thank you. @Bri_G that really did catch me off guard. I do look forward to my combing the code skills improving.
@dave1707 you hit the nail on the head.
I was coming here to report just that. After fixing balloon, I have now ran into two errors, which appear once Codea tries to redraw the balloon.
I checked both code lines mentioned in the error reports.
The error reports state, arrowX is a nil value, but how can that be, when in the function setup arrowX was declared a variable for arrowStartX. Therefore not nil - has a function - thus, providing function draw - parameters to pull from. (This is my thoughts on the issue)
The code is spelled exactly the same as @Ignatz code. I’m definitely stumped as to what is causing the errors. Maybe you can enlighten me on what I did wrong?
Here are the two error reports generated (after the arrow hits balloon):
Main: 72: attempt to perform arithmetic on a nil value
(global ‘arrowX’)
stack traceback:
Main: 72: in function
‘draw’
Referring to this line of code:
Here’s the other error, which appears right below the first error report:
Main: 48: attempt to perform arithmetic on a nil value
(global ‘arrowX’)
stack traceback:
Main: 48: in function
‘draw’
Referring to this line of code:
@tactfulgamer Once I fix the balloonY error, the code runs OK for me. The balloon goes off the top of the screen and reappears at the bottom. Start with your original code and fix the balloonY error and see what happens.
@dave1707 Yes, I did fix balloonY and those are the errors I receive.
See here:
At the end of the Collision Detect code, arrowStart should be arrowStartX.
@dave1707 Now that was a good laugh
Seems I have an affinity for single letters twisting me up.
The good thing in all of this. I can kind of read and understand the code to a degree.
Huge step from where I was at before. Making gains.
Thank you
The more you code and the more mistakes you make and fix, the better you get. So keep on coding and have fun.