Posted: 27th Oct 2022 2:17
Hi, been a long time and i am a little ruty from my rest.

I have a set of ballons I am working on as a learning lesson from the books.

Im taking a lot I have read on and my array will not work. Can some one tell me what i am doing wrong? I understand arrays and know how to use them and this is why I am lost. I guess i do not remember something.

Anyhow, this does not work . the error is "id" Need to be followed by what ever,so on and so forth.

+ Code Snippet
Type All_Ballons
ID
endtype

global  Ballons as All_Ballons[0] 


for A=1 to 5
	
Ballons.ID=LoadSprite("Ballons.png")
SetSpriteAnimation(Ballons.ID,256,256,24)
SetSpritePositionByOffset(Ballons.ID,random(10,750),0)
size=random(60,90)
SetSpriteSize( Ballons.ID, size, size )


ballon=random(1,6)
if ballon=1 then SetSpriteFrame(Ballons.ID,1)
if ballon=2 then SetSpriteFrame(Ballons.ID,5)
if ballon=3 then  SetSpriteFrame(Ballons.ID,9)
if ballon=4 then  SetSpriteFrame(Ballons.ID,13)
if ballon=5 then  SetSpriteFrame(Ballons.ID,17)
if ballon=6 then SetSpriteFrame(Ballons.ID,21)


All_Ballons.ID.Insertsorted(Ballons)

next A
Posted: 27th Oct 2022 3:05
With arrays of types I will define a single type and the array.

As i loop i populate the single type and then insert it into the array.

When i define types a begin the name with a "t". That way I can differentiate between data names and type names

I changed a couple things there to make it a bit more readable.

+ Code Snippet
Type tBallon
	ID as integer
endtype
 
global  All_Ballons	as tBallon[] 

global  Ballon		as tBallon

frame as integer[5] = [1, 5, 9, 13, 17, 21]

 
for A=1 to 5
     
	Ballon.ID=LoadSprite("Ballons.png")
	SetSpriteAnimation(Ballon.ID,256,256,24)
	SetSpritePositionByOffset(Ballon.ID,random(10,750),0)
	size=random(60,90)
	SetSpriteSize( Ballon.ID, size, size )
	 
	SetSpriteFrame(Ballon.ID, frame[random(0,5)])
	
	All_Ballons.Insertsorted(Ballon)
 
next A


Good luck!
Posted: 27th Oct 2022 4:32
Thank you for the help I see what i did in the first place.

Here is my whole program to show as a learning example i created.

LOL, EDIT, I misspelled Balloons with Ballon, well, at least the program does not care lol.

+ Code Snippet
// Project: Balloon POP 
// Created: 2022-10-25

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Balloon POP" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

Type tBalloon
ID as integer
Time
YPos
XPos
Frame
visible
UnderTheLine
Speed
SpriteFrame
Animation
HitTest
GetFrame
endtype

global  All_Balloons as tBalloon[] 
 
global  Balloons      as tBalloon


BackGroundPick=random(1,6)
BackGround=LoadSprite("background-"+STR(BackGroundPick)+".PNG")

//BackGround=LoadSprite("background-2.PNG")


for A=1 to 5
	
Balloons.ID=LoadSprite("Ballons.png")
SetSpriteAnimation(Balloons.ID,256,256,24)
SetSpritePositionByOffset(Balloons.ID,random(10,750),0)
size=random(60,90)
SetSpriteSize( Balloons.ID, size, size )


Balloons.GetFrame=random(1,6)
if Balloons.GetFrame=1 then SetSpriteFrame(Balloons.ID,1)
if Balloons.GetFrame=2 then SetSpriteFrame(Balloons.ID,5)
if Balloons.GetFrame=3 then  SetSpriteFrame(Balloons.ID,9)
if Balloons.GetFrame=4 then  SetSpriteFrame(Balloons.ID,13)
if Balloons.GetFrame=5 then  SetSpriteFrame(Balloons.ID,17)
if Balloons.GetFrame=6 then SetSpriteFrame(Balloons.ID,21)

Balloons.Speed=random(1,5)

All_Balloons.Insertsorted(Balloons)

next A

Collected=0
ang=0
BalloonSpeed=1


CreateText(1,"Collected")
SetTextSize(1,50)
SetTextPosition(1,10,10)


sound_1 = LoadSound("BombExplode.wav")
sound_2 = LoadSound("playerDie.wav")
Music_1=LoadMusic("music.mp3")

SetMusicFileVolume( 1, 50 )
PlayMusic(1)


do
	
for A=All_Balloons.length  to 0 Step -1
	  
    mx#=ScreenToWorldX(GetPointerX())
    my#=ScreenToWorldY(GetPointerY())
    

	
    if getpointerpressed()=1
        All_Balloons[A].HitTest = GetSpriteHitTest (All_Balloons[A].ID, mx#, my# )
        //click offset
        ox# = mx# - GetSpriteXbyoffset ( All_Balloons[A].ID )
        oy# = my# - GetSpriteYbyoffset ( All_Balloons[A].ID )
    endif

    if getpointerreleased()=1
        All_Balloons[A].HitTest = 0
    endif
    
  
All_Balloons[A].Frame=GetSpriteCurrentFrame( All_Balloons[A].ID )
All_Balloons[A].YPos=GetSpriteYByOffset(All_Balloons[A].ID)



if All_Balloons[A].YPos>100 and getpointerpressed() = 1 and All_Balloons[A].HitTest=1 then All_Balloons[A].Animation=1

if All_Balloons[A].Animation=1
if All_Balloons[A].Frame=1 then PlaySprite(All_Balloons[A].ID,5.0,0,1,4)
if All_Balloons[A].Frame=5 then PlaySprite(All_Balloons[A].ID,5.0,0,5,8)
if All_Balloons[A].Frame=9 then PlaySprite(All_Balloons[A].ID,5.0,0,9,12)
if All_Balloons[A].Frame=13 then PlaySprite(All_Balloons[A].ID,5.0,0,13,16)
if All_Balloons[A].Frame=17 then PlaySprite(All_Balloons[A].ID,5.0,0,17,20)
if All_Balloons[A].Frame=21 then PlaySprite(All_Balloons[A].ID,5.0,0,21,24)
PlaySound(sound_1,100,0,0)
All_Balloons[A].Time=-300
All_Balloons[A].XPos=random(10,750)
All_Balloons[A].Speed=5
All_Balloons[A].Animation=0
else
	
inc All_Balloons[A].Time,All_Balloons[A].Speed
inc ang, 1
if All_Balloons[A].Time>100 then SetSpritePositionByOffset(All_Balloons[A].ID,All_Balloons[A].XPos,All_Balloons[A].Time)
SetSpriteAngle(All_Balloons[A].ID,ang)
endif

if All_Balloons[A].Frame=4 then SetSpriteVisible(All_Balloons[A].ID,0)
if All_Balloons[A].Frame=8 then SetSpriteVisible(All_Balloons[A].ID,0)
if All_Balloons[A].Frame=12  then SetSpriteVisible(All_Balloons[A].ID,0)
if All_Balloons[A].Frame=16 then SetSpriteVisible(All_Balloons[A].ID,0)
if All_Balloons[A].Frame=20  then SetSpriteVisible(All_Balloons[A].ID,0)
if All_Balloons[A].Frame=24 then SetSpriteVisible(All_Balloons[A].ID,0)

if All_Balloons[A].Time=205 then All_Balloons[A].visible=1

if All_Balloons[A].visible=1
SetSpriteVisible(All_Balloons[A].ID,1)
All_Balloons[A].GetFrame=random(1,6)
if All_Balloons[A].GetFrame=1 then SetSpriteFrame(All_Balloons[A].ID,1)
if All_Balloons[A].GetFrame=2 then SetSpriteFrame(All_Balloons[A].ID,5)
if All_Balloons[A].GetFrame=3 then  SetSpriteFrame(All_Balloons[A].ID,9)
if All_Balloons[A].GetFrame=4 then  SetSpriteFrame(All_Balloons[A].ID,13)
if All_Balloons[A].GetFrame=5 then  SetSpriteFrame(All_Balloons[A].ID,17)
if All_Balloons[A].GetFrame=6 then SetSpriteFrame(All_Balloons[A].ID,21)
size=random(50,110)
SetSpriteSize( All_Balloons[A].ID, size, size )
All_Balloons[A].visible=0
endif

if All_Balloons[A].YPos=800 and All_Balloons[A].UnderTheLine=0 then All_Balloons[A].UnderTheLine=1

if  All_Balloons[A].UnderTheLine=1
All_Balloons[A].Time=-300
All_Balloons[A].XPos=random(10,750)
SetSpritePositionByOffset(All_Balloons[A].ID,All_Balloons[A].XPos,30)
Collected=Collected-1
PlaySound(sound_2,30,0,0)
All_Balloons[A].UnderTheLine=0
endif

if All_Balloons[A].YPos>100 and GetPointerPressed() = 1 and All_Balloons[A].HitTest=1 then Collected=Collected+1

if All_Balloons[A].Time>800 then All_Balloons[A].Time=-300

SetTextString ( 1, line0$ )
line0$ = "Collected (" + str (Collected ) +")"



next A


    Sync()
loop
Posted: 27th Oct 2022 7:45
Looks good.
Maybe have a look at functions as well
Posted: 27th Oct 2022 8:53
@blink0k

Yes, Right now i am learning how to use the else command to nest information correctly.

When I get to functions I will probebly need some help with something lol.

I know a lot about functions but not everything and there is a lot to learn so this is fun for me to learn and reading the books is making me think wow, there is a lot i have never done correctly.

Thank you for the help.
Posted: 23rd Nov 2022 12:40
functions are handy
for example i made this function if you want to check if an integer equals another integer as it was for print purposes it returned the string
used like print(nottrue(1,2)) prints "True

+ Code Snippet
function notTrue (a as integer,b as integer)
	returnme as string
	if a=b then exitfunction "False"
endfunction "True"


maybe not very handy a function in general but useful in a program I'm working on
Posted: 24th Nov 2022 15:44
@fubarpk
Your function will always return a string that contains True, it needs to be something more like this.

+ Code Snippet
function NotTrue(a as integer, b as integer)
	local flag as integer
	
	if a = b
		flag = 0
		
	else
		flag = 1
		
	endif
	
endfunction flag
Posted: 24th Nov 2022 19:55
Your function will always return a string that contains True, it needs to be something more like this.


Not quite.

it will return "False" if this condition is true

if a=b then exitfunction "False"
Posted: 24th Nov 2022 23:17
@blinkOk

I failed to notice the use of ExitFunction, my bad!