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.

AppGameKit Classic Chat / V2 Ref to Array?

Author
Message
Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 2nd Nov 2014 07:28 Edited at: 2nd Nov 2014 07:30
Is it possible to Return a Reference to an Array From a function

for example:


FUNCTION GetSelectedArray()
SelectionReference = MyArray.NextArray.AnotherArray[index]
ENDFUNCTION SelectionReference

as I read with the new arrays u could pass references INTO a function but I cant figure out how to pass a reference out , as I find this would be quite handy for cutting down on how much coding needs to be done to get down inside encapsulated arrays , I could be pushing my luck with the scope of AppGameKit as I'm really liking the new Array functions but if it IS possible then I would like to know thanks

Native Technology
MikeHart
AGK Bronze Backer
21
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 2nd Nov 2014 11:08 Edited at: 2nd Nov 2014 11:09
Nope, no go. The best is to work with global arrays and access its items through passsing only the index. When you store a type inside an array or retrieve it, you will work with copies of them. You have to access the array element directly. So if you want to access it outside a function, you have to return the index of it.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 2nd Nov 2014 11:35
Native Tech:
I don't think it's possible in the current version.

MikeHart:
In v2 you can pass arrays by reference into a function.

Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 2nd Nov 2014 12:48
Mike thanks for replying

Digital Awakening thanks also

It isnt a major concern i just noticed an oppurtunity to take a shortcut by pointing at an element 3 or more levels deep inside an array i thought AppGameKit might have some pointer/reference/handle method
oh well back to hard coding my references

Native Technology
MikeHart
AGK Bronze Backer
21
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 2nd Nov 2014 19:32
@Native Tech: What are you trying to achieve?

I come from a more object oriented background and at first I thought that I can't reprocduce parts of my engine in AGK2. But with a little thinking and going with the same approach (integer index) for objects like AGK2 does with sprites, I got it nicely working.
Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 2nd Nov 2014 19:55 Edited at: 2nd Nov 2014 19:57
Mike .... Yip thats how i am operating.very similar to OOP using UDTs im setting up a main UDT and encapsulating one that encapsulates another in which further contains another UDT therefor needing a Reference to the "Parent" in which im having to handcode the reference even when using globals i still have to point my functions at the correct index 3 layers deep inside the Parent and atm i am using functions to point to the Parent and then using a for next loop to catch the 2nd level and another for next to catch the 3rd.i will post an example later as i am away atm

Native Technology
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 2nd Nov 2014 22:25
I just skimmed the thread so maybe this has already been said, but instead of returning an array (meaning it has to be copied) I've instead been creating an array before each applicable function and passing a reference to that array into the function.


JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 2nd Nov 2014 22:44
@Native Tech - It's fun devising ways to do this. I've thought about it quite a bit. Really these should be compiler functions to work well.

Better probably to use a real OOP language - in my case Object Pascal - or devise your own language that runs in a tiny interpreter inside AppGameKit Basic.

-- Jim - When is there going to be a release?
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 3rd Nov 2014 02:40 Edited at: 3rd Nov 2014 02:40
Oh, also, I used memblocks in the past to create OOP style data storage. You can use the memblock ID as a pointer. The code starts to look like a mess since you have to use indices (and remember to do a type of garbage collection yourself) but it worked very well here. The original intent was to create dynamic arrays, but that has since been added in AGKv2. Either way, you still have more power using memblocks

Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 3rd Nov 2014 08:27
Thanks Swiss for your input
Jim I believe ur right, adding an actual pointer setup would make life a bit easier but, basically a reference that points to the address given is all that is needed and then we could pass the reference around as need be, however I doubt if we would be getting that functionality any time soon

Native Technology
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 3rd Nov 2014 09:29
Actually Swissolo's example more or less does this.

A lot depends on how the interpreter handles memory, stacks and heaps.

-- Jim - When is there going to be a release?
Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 3rd Nov 2014 10:27 Edited at: 3rd Nov 2014 10:29
Awesome and yip swiss solos example will work on the top level but I cant see it working as I descend down through the levels so just to clarify what Exactly I was hoping for is something which does the following






And so I have created an array of TYPE SEQUENCE


GLOBAL SEQ AS SEQUENCE[]

and one of the Possible paths down into the lower levels could possibly look like this


SEQ[index].ROW[rowID].SprID[2] = CreateSprite(1,1)

and in theory I would be descending through the levels each time coding it out like that OR even using a function to Get the "index" of each Level required , but what I'm actually asking in the original post is.... is it possible to create a pointer from the path given

eg:

MyRef as Pointer


MyRef = SEQ[index].ROW[rowID].SprID[2]



so that each time I need to access it rather than writing out the entire path to the bottom level I would just pass MyRef to my functions and have them operate at that level as at the moment I am currently using a GET function to point me there where as I beleieve pointers would solve this problem with the Overall objective of using LESS lines of code to get to the index rather than manipulating global indexes and rather than using memblocks which would be defeating the purpose of using less code , pretty simple solution to a pretty simple problem, but like I say I am coding it in this fashion and it is working , I would just like to take shortcuts haha

Native Technology
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 3rd Nov 2014 11:44
Frankly, this looks to me unnecessarily complicated. Why not use Midi tracks? They're easy to parse and convert to another format if necessary. You could use CONTROL items to add sprite information.

I programmed a Music Composition Language for the Amiga that Ariadne published back in the good old days, and I was thinking of doing something similar for AGK. For real-time playback you need something that's very fast to read.

-- Jim - When is there going to be a release?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Nov 2014 12:58 Edited at: 3rd Nov 2014 13:01
Quote: "
MyRef as Pointer
MyRef = SEQ[index].ROW[rowID].SprID[2]
"


what about this?


AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 3rd Nov 2014 18:46 Edited at: 3rd Nov 2014 18:54
Thats awesome jim
thanks markus i could have a play with that later

Native Technology
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 4th Nov 2014 00:33
@ Native Tech - I think it's important sometimes to remember that you have to play to the strengths and avoid the weaknesses of what you're working with. Trying to do modern OOP programming with AppGameKit Basic is intellectually interesting and fun but likely to be very inefficient.

My view is to think about the most efficient way for playback or load of your levels or music tracks or AI, and then program design and edit tools on a desktop system. With an interpreted run-time system on potentially rubbish hardware all the difficult maths should, as far as possible, not be done at run-time.

Those of us with grey or white or any hair remember 8-bit computers and having sin look-up tables instead of trying to do that on the fly. Those days may be back.

I think the ref ability is a major step forward for AppGameKit Basic, but it's never going to walk on water, is it?

-- Jim - When is there going to be a release?
Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 4th Nov 2014 08:23
The way I have approached it is actually easier to Debug ... easier to Design and in effect has made the entire process easier to Develop ... 3 D's covered? all I really wanted to know was can I get references to elements?...it seems not, I'm happy with the new approach to arrays

Native Technology

Login to post a reply

Server time is: 2024-11-25 11:36:45
Your offset time is: 2024-11-25 11:36:45