Types in AGK

Started by Santiago, May 17, 2020, 22:34:45

Previous topic - Next topic

Santiago

hi, i am trying to understand the "TYPES" in AGK.

in blitz3d I used like this



type ship
    field pivot
end type


function update_ships()

  for s.ship = each ship     <<<<< how can i do this in agk?   
    moveentity s\pivot,0,0,1
  next

end function




In AGK, how can I do this as I did in blitz?

Santiago

i don't like to use array, just type


this is and example demo from forum, i don't like this array thing...

// Project: xypositions
// Created: 2020-03-17

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "xypositions" )
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( 30, 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 _xyPositions
x as float
y as float
endtype

xyPosition as _xyPositions

//Create a variable array
xyPos as _xyPositions[]

xyPosition.x = 10
xyPosition.y = 20
xyPos.insert(xyPosition)

do
for a=0 to xyPos.length
print(xypos[a].x)
print(xypos[a].y)
next

   

    Print( ScreenFPS() )
    Sync()
loop

blinkok

I think your stuck with arrays there.
I don't think AGK has a type that works like that
How do you add entries to a type like that?

Qube

#3
Yup, in AGK you do need to use arrays when using types.

But it does have some handy things.

Code (AGK) Select

// Yes we're using Globals here so we can access the types from any part of our sloppy coding

Type tGuys
x As Float
y As Float
shootAtGuy As Integer
EndType

Global Guy As tGuys
Global Guys As tGuys[]

Local count As Integer

For count = 1 To 1000
Guy.x = Random2( 0, 1919 )
Guy.y = Random2( 0, 1079 )
Guys.insert( Guy )
Next

// Now imagine the functions below are complex routines for our guys but want to keep our code neat then we can do this...

For count = Guys.length To 0 Step -1 // we go backwards in case we need to delete a guy. Going forward and deleting will cause an error
MoveGuys( Guys[ count ] )
ShootAtGuy( Guys[ count ],  Random2( 0, 999 ) )
Next

Function MoveGuys( myGuy Ref As tGuys )
myGuy.x = Random( 0, 1919 )
myGuy.y = Random( 0, 1079 )
EndFunction

Function ShootAtGuy( myGuy Ref As tGuys, shootAt As Integer )
myGuy.shootAtGuy = shootAt
EndFunction
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.


Santiago

thanks for the example!, is very clear!

ok, i go to lean to use like AGK way from now  8)

hosch

Quote from: Qube on May 18, 2020, 04:42:08
Yup, in AGK you do need to use arrays when using types.

But it does have some handy things.

Code (AGK) Select

// Yes we're using Globals here so we can access the types from any part of our sloppy coding

Type tGuys
x As Float
y As Float
shootAtGuy As Integer
EndType

Global Guy As tGuys
Global Guys As tGuys[]

Local count As Integer

For count = 1 To 1000
Guy.x = Random2( 0, 1919 )
Guy.y = Random2( 0, 1079 )
Guys.insert( Guy )
Next

// Now imagine the functions below are complex routines for our guys but want to keep our code neat then we can do this...

For count = Guys.length To 0 Step -1 // we go backwards in case we need to delete a guy. Going forward and deleting will cause an error
MoveGuys( Guys[ count ] )
ShootAtGuy( Guys[ count ],  Random2( 0, 999 ) )
Next

Function MoveGuys( myGuy Ref As tGuys )
myGuy.x = Random( 0, 1919 )
myGuy.y = Random( 0, 1079 )
EndFunction

Function ShootAtGuy( myGuy Ref As tGuys, shootAt As Integer )
myGuy.shootAtGuy = shootAt
EndFunction


Thanks so much! I am porting my Blitz3D game to AGK and was using types extensively and this helped me out big time!