Ooops
May 31, 2020, 09:36:03 PM

Author Topic: Types in AGK  (Read 168 times)

Offline Santiago

  • Full Member
  • ***
  • Posts: 215
  • Blitz3d
    • Indiesoft
Types in AGK
« on: May 17, 2020, 10:34:45 PM »
hi, i am trying to understand the "TYPES" in AGK.

in blitz3d I used like this

Code: [Select]

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?

Offline Santiago

  • Full Member
  • ***
  • Posts: 215
  • Blitz3d
    • Indiesoft
Re: Types in AGK
« Reply #1 on: May 17, 2020, 10:43:24 PM »
i don't like to use array, just type


this is and example demo from forum, i don't like this array thing...
Code: [Select]
// 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

Offline blinkok

  • Full Member
  • ***
  • Posts: 170
Re: Types in AGK
« Reply #2 on: May 18, 2020, 04:08:56 AM »
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?

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 2373
Re: Types in AGK
« Reply #3 on: May 18, 2020, 04:42:08 AM »
Yup, in AGK you do need to use arrays when using types.

But it does have some handy things.

Code:  (Unknown Language)
  1. // Yes we're using Globals here so we can access the types from any part of our sloppy coding
  2.  
  3. Type tGuys
  4.         x As Float
  5.         y As Float
  6.         shootAtGuy As Integer
  7. EndType
  8.  
  9. Global Guy As tGuys
  10. Global Guys As tGuys[]
  11.  
  12. Local count As Integer
  13.  
  14. For count = 1 To 1000
  15.         Guy.x = Random2( 0, 1919 )
  16.         Guy.y = Random2( 0, 1079 )
  17.         Guys.insert( Guy )
  18. Next
  19.  
  20. // Now imagine the functions below are complex routines for our guys but want to keep our code neat then we can do this...
  21.  
  22. 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
  23.         MoveGuys( Guys[ count ] )
  24.         ShootAtGuy( Guys[ count ],  Random2( 0, 999 ) )
  25. Next
  26.  
  27. Function MoveGuys( myGuy Ref As tGuys )
  28.         myGuy.x = Random( 0, 1919 )
  29.         myGuy.y = Random( 0, 1079 )
  30. EndFunction
  31.  
  32. Function ShootAtGuy( myGuy Ref As tGuys, shootAt As Integer )
  33.         myGuy.shootAtGuy = shootAt
  34. EndFunction
  35.  
Until the next time...

Offline blinkok

  • Full Member
  • ***
  • Posts: 170

Offline Santiago

  • Full Member
  • ***
  • Posts: 215
  • Blitz3d
    • Indiesoft
Re: Types in AGK
« Reply #5 on: May 18, 2020, 12:50:39 PM »
thanks for the example!, is very clear!

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

Offline hosch

  • Jr. Member
  • **
  • Posts: 20
Re: Types in AGK
« Reply #6 on: May 23, 2020, 01:25:19 PM »
Yup, in AGK you do need to use arrays when using types.

But it does have some handy things.

Code:  (Unknown Language)
  1. // Yes we're using Globals here so we can access the types from any part of our sloppy coding
  2.  
  3. Type tGuys
  4.         x As Float
  5.         y As Float
  6.         shootAtGuy As Integer
  7. EndType
  8.  
  9. Global Guy As tGuys
  10. Global Guys As tGuys[]
  11.  
  12. Local count As Integer
  13.  
  14. For count = 1 To 1000
  15.         Guy.x = Random2( 0, 1919 )
  16.         Guy.y = Random2( 0, 1079 )
  17.         Guys.insert( Guy )
  18. Next
  19.  
  20. // Now imagine the functions below are complex routines for our guys but want to keep our code neat then we can do this...
  21.  
  22. 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
  23.         MoveGuys( Guys[ count ] )
  24.         ShootAtGuy( Guys[ count ],  Random2( 0, 999 ) )
  25. Next
  26.  
  27. Function MoveGuys( myGuy Ref As tGuys )
  28.         myGuy.x = Random( 0, 1919 )
  29.         myGuy.y = Random( 0, 1079 )
  30. EndFunction
  31.  
  32. Function ShootAtGuy( myGuy Ref As tGuys, shootAt As Integer )
  33.         myGuy.shootAtGuy = shootAt
  34. EndFunction
  35.  

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

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal