Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Sprite xxx doesn't exist in xxx at line xx error

Author
Message
nickydemon
9
Years of Service
User Offline
Joined: 19th May 2015
Location:
Posted: 1st Sep 2019 16:18
I don't understand why I am getting this error. I have two agc that separates like following:

main.agc


sprite.agc


When I run the above code it gave me "sprite 50000 doesn't exist in sprite.agc at line 18".
However if i comment out InitPlayerPosition and use player.x = GetVirtualWidth() / 2 - GetSpriteWidth(player.image), it doesn't show any error and my sprite show in the middle(this is what i wanted).

I can't tell the difference between these two codes.
Is this a bug or I did something wrong?
kragoth74
7
Years of Service
User Offline
Joined: 3rd May 2017
Location:
Posted: 1st Sep 2019 17:55
You should use
instead of
at line 18 of sprite.agc. Your'e asking for the width of the sprite but you pass an image as parameter.
kragoth74
7
Years of Service
User Offline
Joined: 3rd May 2017
Location:
Posted: 1st Sep 2019 17:57
, to be precise.
nickydemon
9
Years of Service
User Offline
Joined: 19th May 2015
Location:
Posted: 2nd Sep 2019 13:31
Hi kragoth74, thank you for your reply.
Actually I did try player.sprite and player.image before that and it still showed the same result.
And both player.sprite and player.image works again if they are outside the function scope.
Is this possibly a bug?
kragoth74
7
Years of Service
User Offline
Joined: 3rd May 2017
Location:
Posted: 2nd Sep 2019 13:53 Edited at: 2nd Sep 2019 13:54
I would change 2 things:

1, use a different name for the player type and the actual player object, for example

to avoid any confusion.

2, simplify the InitPlayerPosition function
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 14th Sep 2019 11:40 Edited at: 14th Sep 2019 12:05
Quote: " both player.sprite and player.image works again if they are outside the function scope."

Sounds like a Global declaration issue.

Quote: "global player as Player"


Quote: "function InitPlayerPosition( a ref as Player)"


player is global, but is Player?

so, is a global?

Try changing the p in Player to lower case in your original code at line 18 and see what happens.

EDIT
OOPS, I had overlooked the ref part.
According to the Documentation, that should have worked.
You could still try it though to see if the REF is the bug.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 14th Sep 2019 13:52 Edited at: 15th Sep 2019 12:35


You divide the ID (a.image) with 2 inside the function parameter list for GetSpriteWidth(). The division should be outside the parameter list so you get the exact ID.

EDIT: Just on a sidenote, you get the ID for a.image in GetSpriteWidth, my guess is that it should be a.sprite, but it still runs because a.image and a.sprite happens to have the same ID number, something like 100001, and they're the same because it is the first created image and the first created sprite.
13/0

Login to post a reply

Server time is: 2024-11-21 12:43:05
Your offset time is: 2024-11-21 12:43:05