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 / Is there a command to check if an array excist?

Author
Message
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 17th Nov 2014 20:27
Well, is there? If not, shouldn't there be one?

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Nov 2014 20:30
I think that it is assumed that you will know if you created an array or not.
It would be useful, but you can work around it. Have a variable that you set to 1 when the array is created.

Quidquid latine dictum sit, altum sonatur
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 17th Nov 2014 22:20
Yeah, you can work around it. But we can dim and undim arrays, which makes a lot of sense since we are likely to load and unload levels. Among other things. I can think of a lot of reasons to be able to check if an array currently exists. Since we can do so much more with arrays now, it just makes even more sense.

Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 17th Nov 2014 22:21
had this issue also but managed to work around it by using

if myarray.length =-1 then dontwritehere

or if myarray.length =-1 then myarray.length = newsize

its ugly but its error handling has worked wonders for my UDTs

Native Technology
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 17th Nov 2014 22:25
in v2 we have .length , i believe arrays are still global and exist always.
in v1 i missed lbound & ubound

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 17th Nov 2014 22:33
Native Tech:
Ah, if an undimed or undefined array reports as -1 then I am happy. Thanks

Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 18th Nov 2014 00:21
iv been enjoying v2 arrays they are awesome.however o believe
pointers would solve this and numerous other array dramas

for example an array thats inside a udt would b noce to get a pointer to the lower level array rather than
having to hardcode the path all the way down.especially when working with grids where u might have
an array of screens which contain gridlines which contain xy coordinates

type grid
horizontals as integer[]
verticals as integer[]
endtype

where the path to an x coordinate might look like this

grid.horizontal.x[1]

and having to pass that data around numerous times would require dumping that element into a global variable

but would b easier to say

ptrX = grid.horizontal.x

and u would then b able to see if the array x even exists and if so
then u would navigate the index using the pointer

Native Technology
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 18th Nov 2014 01:16
I don't understand any of this. If the array did not exist the compiler would reject it, unless you turned strict mode off, which would be rather silly.

As for the second example, the x and y should be in a point type. Then there is no problem doing anything with it at any depth.

Using un-typed pointers can be very dangerous. In a virtual system like AppGameKit Tier 1 a "pointer" could only point to an area in the virtual memory space. memory allocation and disposal is a complicated issue. In order to use un-typed pointers you need to have some casting mechanism.

The advantage of typed pointers is that they give you dynamic memory management. Pascal and C have both had that since the late sixties:

var intPtr: ^integer; // a pointer to a type

new(intPtr); // allocate the memory

intPtr^ := 54; // de-reference the pointer and store 54 there

Dispose(intPtr); // free the memory back to the memory pool

This preceded OOP programming, which builds on this to make things much more dynamic. For very big programs it's vital to be able to create and destroy lots of entities rather than have them all in memory from the start.

-- Jim - When is there going to be a release?
Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 18th Nov 2014 05:39
Digital Awekening let me know how u get on with the -1 check

I dont dim arrays as I've been declaring them with the new style arrays in V2

thisarray as integer[]


and then adjusting the size with


thisarray.length = newsize



I have no issues with the arrays as I've used -1 to determine the action I take on them and I've managed to work right around everything by simply applying the -1 check so I have UDT's which contain arrays of UDT's which for some may be too much to comprehend but in reality is very very basic and probably the most effective way I have found so far to use the new arrays , with this style u can create Levels , scenes , tiles , inventories , GUI Menus , grids , and u can attatch properties to each tile if u wish and it would all be contained inside a UDT , so u could literally check ur collision types or ur events from inside ur UDT , u can use the UDT to check if a door is opened , if a playersprite has collided with any 1 of 1000 tile sprites , it would trigger the appropriate action because all details needed a stored inside a UDT , maybe not on the first index , but deeper inside a subarray , or even inside a subarray that is inside a subarray

Does this make sense? , basically what u will find is that rather than coding thousands and thousands of lines of code over and over again , u can just use the one template UDT , create a new instance of it using

UDT.length = UDT.length+1

and ALL subarray data structures will then automatically be created because it is all contained inside the TOP LEVEL UDT , therefor giving u endless options as to what u wanna use them for and a template in which u can scale to a factor only limited by ur imagination , allowing u to create hundreds of levels on the fly and upon creating them it can automatically fill ur event details wether its collision or whatever u can imagine,this will save u ridiculous amounts of coding time

if u design in this manner u will finish projects faster meaning if ur doing this professionally u can start working on ur marketing sooner , because production times will speed up, I thought this is how most people were coding anyway? , YES I come from an OOP background and YES I realise that AppGameKit is no Object Orientated , but the new arrays are something special and should be used in such a manner , I'm not trying to C++ or Pascal these arrays , I am just using them in a very pratical manner , ur limited only by ur imagination when programming , and for the purpose of remaining on topic for the original thread YES I do think being able to check if an array exists would be very very helpful , and the closest thing I've come to it is to make sure that the UDT that I am checking does NOT = -1

Native Technology
Native Tech
11
Years of Service
User Offline
Joined: 19th Jul 2013
Location:
Posted: 18th Nov 2014 05:46
forgot to smile

Native Technology

Login to post a reply

Server time is: 2024-11-25 11:32:14
Your offset time is: 2024-11-25 11:32:14