#πŸ”’ I don't understand this error message, what is it, and how do I fix it?

105 messages Β· Page 1 of 1 (latest)

inland timber
#

I'm learning python through a course called CMU CS acamdemy and I'm making a little fish game where you play as a shark.
Im running a code using onstep where every 30 frames (stepsPerSecond = 30)
a counter counting in game seconds goes up by 1. When 10 seconds have passed the first wave starts which spawns a certain amount of fish:

(here is the fish spawn code that also spawns a hitbox for each fish)

fishys = Group()
fishHitboxes = Group()

def spawnfish():
y=randrange(100,400)
fishHitbox = Oval (400,y,110,40, fill = 'red')
fish = Image('cmu://744624/30765862/Screenshot_2024-05-06_at_8.50.42_AM-removebg-preview.png',400,y)
fish.width = 90
fish.height = 60
fish.speed = randrange(-6,-1)
fishHitbox.speed = 0
fishHitboxes.add(fishHitbox)
fishys.add(fish)
app.fishtotal += 1

(here is the control for each fish movement and each hitbox movement, it also interacts with the shark hitbox (shonkHitbox))

for fish in fishys:
for fishHitbox in fishHitboxes:
fishHitbox.opacity = 100
fish.centerX += fish.speed
fishHitbox.centerX = fish.centerX
fishHitbox.centerY = fish.centerY
if (fish.centerX < 0):
del fish
if (fishHitbox.hitsShape(shonkHitbox)):
del fish

(here is the wave and seconds counter, this also has a limiter so infinite fish don't spawn because this line of code is in the onstep.)

if app.counter % 30 == 0:
app.seconds += 1

if (app.seconds == app.waveinterval):
    app.waveinterval += 10
    app.wave += 1

if (app.wave ==1):
    app.fishlimit = 12
    if (app.fishtotal < app.fishlimit):
        spawnfish()

(when wave 1 starts I receive this error message)

"line 214:
fish.centerX += fish.speed
Exception: <Javascript TypeError>: Cannot read properties of undefined (reading 'js_getattribute')"

half kilnBOT
#

@inland timber

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

inland timber
#

(please ping me if you have an answer I do not mind at all and it makes it easier for me to see it)

twilit stratus
#

how is that says javascript error if you are using python?

inland timber
#

cmu cs is a website

#

im guessing its something to do with that

#

but yeh i have no idea

lime minnow
#

You're running the code on the website?

#

That's probably not an error with your code.

#

@inland timber can you run the code on your local machine?

heady gull
#

the error is just saying that centerX isn't an attribute of fish

#

Mako can you show the definition of fish

soft bramble
#

the variable names

inland timber
# heady gull Mako can you show the definition of `fish`

def spawnfish():
y=randrange(100,400)
fishHitbox = Oval (400,y,110,40, fill = 'red')
*here it is ----> *fish = Image('cmu://744624/30765862/Screenshot_2024-05-06_at_8.50.42_AM-removebg-preview.png',400,y)
fish.width = 90
fish.height = 60
fish.speed = randrange(-6,-1)
fishHitbox.speed = 0
fishHitboxes.add(fishHitbox)
fishys.add(fish)
app.fishtotal += 1

inland timber
soft bramble
#

you should install vscode + python

inland timber
#

ive only used and ran python through this website directly

soft bramble
#

vscode allows you to edit the code

inland timber
#

python allows me to run it?

soft bramble
#

yea

#

you can install something like pygame if you're trying to create a game

inland timber
#

even if it gets rid of the error message theres an issue that I can visually see but i thought it might just be because of the error

#

the fish hitboxes i currently made visible so i can see them

soft bramble
#

is the site using pygame?

inland timber
#

in the frame before crash they go into random spots nowhere near the fish that theyre assigned to

inland timber
soft bramble
#

yea you gotta move to something like pygame

#

websites are weird in general

#

i'm pretty sure it uses pygame tho

inland timber
#

i have to go i will try that later

#

thank you

soft bramble
#

πŸ‘

grim spade
inland timber
#

its basically just a sqaure with the image on it

soft bramble
inland timber
#

yes

#

i am installing python

soft bramble
#

yea its just better to install python

lime minnow
#

That way you don't have to question whether or not it's just the website being weird.

#

And also you don't have to use their weird file loading stuff.

#

Do you have to do tests on the site?

inland timber
#

is there anything important i should put here

lime minnow
#

Is it going to grade your code on the site?

inland timber
#

wdym tests?

soft bramble
#

i'm not sure how this works on mac

inland timber
#

oof

soft bramble
#

copy that path just in case it doesn't automatically add to the env

lime minnow
#

Sometimes website courses have exams on the site and they require you to write code on the site for those tests. I was just wondering if that was the case for the course you are taking.

inland timber
#

oh i see

lime minnow
inland timber
#

so pretty much this is a "creative task" i just kinda make something that shows i understand what i learned

#

but i got bored

#

and made a complex game with 1000+ lines of code

#

which was not at all the intention

soft bramble
#

about fish

inland timber
#

yesh

#

i love fish <3

soft bramble
#

you should add whales too

inland timber
#

maybe

#

currently theres 5 types of fish

#

tuna are fast and have above average hp

#

mahi are slow and can eat other fish

soft bramble
#

you have testers for the game? πŸ˜ƒ

inland timber
#

sardines spawn in schools and require you to kill every one of them to actually gain points

#

and angelfish have low hp but move incredibly fast

#

then theres just the standard "fish"

inland timber
#

maybe when its not broken

soft bramble
#

if something i could become 1

inland timber
#

hopefully i can fix it

#

sure

#

if u want

#

the game is terrible tho

soft bramble
#

no way

inland timber
#

it also has a "frenzy" mechanic to make it more interesting

soft bramble
#

tester fish game o_O

soft bramble
#

are you planning on making another 1 after this?

inland timber
#

i want to make this a real game

#

so if i can fix it ill just keep making it better

#

if i cant im going to start fresh with the same ideas

soft bramble
#

i see

#

pygame does offer a lot of freedom tho

inland timber
#

argh

#

i have no idea how to import my code into python this isnt going to be fun 😭

soft bramble
#

can you send me like the first 10 lines of the code

#

in the website version

#

do you have any imports

inland timber
#

imports?

soft bramble
#

imports are for libraries, for example

#

if you're using something like pygame, you'd have to do import pygame to use the library

inland timber
#

i uh

#

dont know if i can do that

#

or how i even would

soft bramble
#

you installed python right

inland timber
#

gtg

#

i will try all this later

#

thanks

soft bramble
#

alright

half kilnBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.