Ooops
April 08, 2020, 07:58:32 AM

Author Topic: So, no linked lists in AGK. How do i?  (Read 4620 times)

Offline playniax

  • Full Member
  • ***
  • Posts: 123
    • Playniax
Re: So, no linked lists in AGK. How do i?
« Reply #30 on: March 07, 2018, 07:58:01 AM »
playing with AGK Tier 1 right now and I can't seem to find a way to compare elements in an array?!

Example that doesn't work but shows what I am trying to do:

Code: [Select]
tiles As TTile[8]

tile As TTile
tiles[4].insert(tile)

for i = 0 to tiles.Length
if tiles[i]=tile Then do something...
next i

Who is bright enough?

Offline therevills

  • Hero Member
  • *****
  • Posts: 595
Re: So, no linked lists in AGK. How do i?
« Reply #31 on: March 07, 2018, 08:13:01 AM »
My guess its because you are not comparing objects you will need to compare attributes:
Code: [Select]
if tiles[i].x=tile.x And tiles[i].x=tile.y And tiles[i].id=tile.id  Then do something...
next i

But I havent coded in AGK...

Offline MikeHart

  • Hero Member
  • *****
  • Posts: 651
Re: So, no linked lists in AGK. How do i?
« Reply #32 on: March 07, 2018, 08:16:24 AM »
Exactly. In AGK you need to get rid of any OBJECT thinking. Give each tile an index. Compare this.

Offline playniax

  • Full Member
  • ***
  • Posts: 123
    • Playniax
Re: So, no linked lists in AGK. How do i?
« Reply #33 on: March 07, 2018, 09:18:24 AM »
I understand what you are saying and I got creative by giving the tile a unique id when it is in the tilemap ( I need to have unique identifiers in my case ) but I am very keen on performance and this just adds more complexity.

I still want to know if it was possible because at the end of the day it is still an object.

So far enjoying AGK and will do some stress testing for sure.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2832
Re: So, no linked lists in AGK. How do i?
« Reply #34 on: March 07, 2018, 09:35:33 AM »
@ therevills
if the .id was unique, I would avoid doing .x and .y property testing - should shape of some cpu cycles :-)

@ playniax
As there are no indices in AGK arrays - but "keys", you cannot do a "0 to x" check. It is more kind of a BlitzMax TMap - so "ValueForKey()" rather than TList's "ValueAtIndex()".
Dunno how AGK handles the whole thing, but unique IDs sound like a big hashmap storing all the stuff. But this would increase lookup time - so maybe they do it for each "type"?

Everything I read here about AGK makes me think it is more compareable to the way Blitz3D and also BlitzMax are exposing convenience functions (namespace polluting "CreatePixmap()"  compared to "new TPixmap.Create()"). You have a long list of commands without any hierarchy.
But I am pretty sure somebody thought about all this before coding, so there must be a benefit in using that "id" stuff compared to object handles.


bye
Ron

Offline therevills

  • Hero Member
  • *****
  • Posts: 595
Re: So, no linked lists in AGK. How do i?
« Reply #35 on: March 07, 2018, 09:19:50 PM »
@ therevills
if the .id was unique, I would avoid doing .x and .y property testing - should shape of some cpu cycles :-)

Yeah I know, I was just "guessing" on the solution and showing an example :)

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal