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.

Raspberry Pi / [Sapce Shooter Tutorial] Error

Author
Message
Naskingar
6
Years of Service
User Offline
Joined: 14th Jul 2017
Location:
Posted: 14th Jul 2017 23:47
Hello, I have tried making the space shooter tutorial under RaspPi 3B and Arch with lxde DE, and I am at the MainMenu step and I encounter the "Error: Sprite 4 does not exist in mainmenu.agc at line XX" error, could somebody help me please?

Here are the main.agc content:

// Project: Engage
// Created: 2017-07-13

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Engage" )
SetWindowSize( 600, 600, 0 )
SetWindowAllowResize( 0 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 600, 600 ) // doesn't have to match the window
UseNewDefaultFonts(1)

playerx as float
playery as float
lazerx as float = -100
lazery as float
lazer_fired = 0

enemyx as float
enemyy as float
enemy_direction = 4
enemy_fired=0
gameover=1

score=0
hiscore=0

#include "Loader.agc"
#include "PlayerMove.agc"
#include "Player_shoots.agc"
#include "enemy_move.agc"
#include "Collision.agc"
#include "stars.agc"
#include "Text.agc"
#include "sounds.agc"
#include "mainmenu.agc"

Gosub loader
Gosub Make_stars
Gosub Make_text
Gosub Load_sounds
Gosub Load_Music

do
if gameover=1
Gosub MainMenu
score=0
endif

Gosub PlayerMove
Gosub Player_shoots
Gosub Enemy_move
Gosub Enemy_Shoot

Gosub Move_stars

Gosub Collision
Sync()
loop


And the Loader.agc:

loader:

// Player Ship =1
// Player Lazer = 2
// Enemy Ship = 3
// Stars = 5 to 104
// Enemy Bullets = 110 to 114

loadimage(1,"player_ship.png")
loadimage(2,"lazer.png")
loadimage(3,"enemyship.png")
loadimage(4,"enemyfire.png")

// Create the player ship and place at the bottom of the screen
CreateSprite(1,1)
playerx=GetVirtualWidth()/2 - GetSpriteWidth(1)/2
playery=GetVirtualHeight()-GetSpriteHeight(1)

SetSpritePosition(1,playerx,playery)

//Create the lazer and move it off screen
CreateSprite(2,2)
SetSpritePosition(2,-100,-100)

// Create the enemy ship and place at the top of the screen

CreateSprite(3,3)
SetSpritePosition(3,100,20)

// Create 5 enemy bullets
for i=0 to 4
CreateSprite(110+i,4)
next i

Return


And finally the mainmenu.agc content:

MainMenu:

Createtext(2,"Engage")
SetTextSize(2,100)
SetTextPosition(2,(600-GetTexttotalwidth(2))/2,180)

Createtext(3,"High Score: ")
SetTextSize(3,60)
SetTextPosition(3,600-GetTexttotalwidth(3),0)

Createtext(4, "Fire to start game")
SetTextSize(4,60)
Settextposition(4,(600-GetTexttotalwidth(4))/2,400)

gosub Hidegamesprites
gosub showmenutext

repeat
sync()
until GetPointerPressed()=1

gameover=0
gosub Showgamesprites
gosub Hidemenutext

Return

// Player Ship =1
// Player Lazer = 2
// Enemy Ship = 3
// Stars = 5 to 104
// Enemy Bullets = 110 to 114

Hidegamesprites:
for i=1 to 114
SetSpriteVisible(i,0)
next i
Return

Showgamesprites:
for i=1 to 114
SetSpriteVisible(i,1)
next i
Return

Hidemenutext:
SetTextVisible(2,0)
SetTextVisible(4,0)
Return

Showmenutext:
SetTextVisible(2,1)
SetTextVisible(4,1)
Return


Thanks and cheers,
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 15th Jul 2017 16:42 Edited at: 15th Jul 2017 16:46
I need to see the content of your stars.agc, because that is where sprite 4 should be created.

EDIT: Hold on, not stars.agc, that starts at sprite 5.

EDIT 2: What does "line XX" say?
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 15th Jul 2017 16:46
Quote: "// Player Ship =1
// Player Lazer = 2
// Enemy Ship = 3
// Stars = 5 to 104
// Enemy Bullets = 110 to 114"


This doesn't say anything about a sprite 4.
13/0
Naskingar
6
Years of Service
User Offline
Joined: 14th Jul 2017
Location:
Posted: 15th Jul 2017 18:29
Thanks for looking into my problem, it says line "36".
--
Naskingar
Naskingar
6
Years of Service
User Offline
Joined: 14th Jul 2017
Location:
Posted: 15th Jul 2017 18:31
Here is the code responsible of sprite 4 I think:

// Create 5 enemy bullets
for i=0 to 4
CreateSprite(110+i,4)
next i
--
Naskingar
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 16th Jul 2017 14:41
Quote: "it says line "36"."


I can't see the line numbers in what you posted, you need to copy/paste that line from your code to here

Quote: "for i=0 to 4
CreateSprite(110+i,4)
next i"


The for loop goes from i = 0 to i = 4, then at CreateSprite, it first creates a sprite with ID 110 (110 + i, where i = 0), then a sprite with ID 111 (110 + i, where i = 1), then a sprite with ID 112 (110 + i, where i = 2). This pattern continue up to ID 114.

The CreateSprite syntax is CreateSprite( manual sprite ID number here, ID of image to use for sprite here)
The last number (4) in your CreateSprite is actually the ID of image to use, not a sprite ID.

You can also have CreateSprite auto assign an available ID to the sprite like this: variable_to_contain_sprite_ID = CreateSprite( ID of image to use for sprite ), this will automatically give you an sprite ID stored in the variable, then you can manipulate that sprite using the variable as an ID, like this SetSpritePosition( variable_to_contain_sprite_ID , 20 , 30 ) (where 20 is the X value and 30 is the Y value).
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 19th Jul 2017 08:57
Did you solve your problem?
13/0

Login to post a reply

Server time is: 2024-04-23 10:18:37
Your offset time is: 2024-04-23 10:18:37