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 / type pointers

Author
Message
dooz
19
Years of Service
User Offline
Joined: 22nd Sep 2005
Location:
Posted: 5th Jan 2016 20:26
I know you can have a type or array passed by ref(erence) to a function. However, can you have a pointer to a type as a local variable, or within another type in Tier 1?

I tried to use "ref" and 0 (since I couldn't find a NULL), they don't work - see example:

myTypePtr ref as MyType
myTypePtr = 0

or

type MyOtherType
myTypePtr ref as MyType
endype



mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 5th Jan 2016 22:21
First off: what are you trying to achieve?

What you describe isn't possible with Tier 1 (it would be nice if I am wrong). You could declare it as global if you need to access it elsewhere or to persist it beyond its current scope. I consider it a hack, but I do it because I don't care. I recommend trying Tier 2's C++ if you want object oriented. There are ways you can do a pseudo-OOP methodology like you would with C structs, but in the end BASIC seems to just boil down to integer IDs to keep track of data. I tend to stay away from relying heavily on refs since I have had some issues with passing a ref to a function which sends the ref to other functions, etc. It lead to a not so awesome experience.
make -C ../NagGaCreMo/2016 -f aGame.mk
dooz
19
Years of Service
User Offline
Joined: 22nd Sep 2005
Location:
Posted: 5th Jan 2016 22:41
Thanks mrradd. I am simply trying to do a bit of OO composition, referencing a type defined elsewhere, rather than containing it. I currently use array indexes, but that's tedious to code when you have to access a field several levels deep.

I take your point about global, maybe that might solve a couple of uses - let the OO go!

By the way, with Tier 2 (not looked at it), is it just a library you use natively, e.g. build an iOS / C++ app in XCode, use the library for cross-platform capabilities?
mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 5th Jan 2016 23:06 Edited at: 5th Jan 2016 23:11
Yes, and no, for Tier 2. The templates out of the box are just drag and drop--just remember to build you NDK if you are developing on Android https://forum.thegamecreators.com/thread/216124! For Mac, you need a Mac, Android use the Android Studio, Windows use Visual Studio 2015 since it gives you access to C++11 functionality (some fancy tools in there that previous versions didn't have). I say yes and no, because you need a separate project for each one but the AppGameKit portion is the same. Some copy pasta is inevitable.

At first I was not a fan of using BASIC, but I forced my self to learn it as a challenge and now I actually like it. Re-wrapping my head around procedural programming forced me to get creative, and since the debugger is still very young it has forced me to code TIGHT--like airlock tight. I make use of Types, arrays with my type "objects", and LOTS of globals (because it just makes life easier even though it's a hack imo). For instance I like to make "constructors" that return an "object" rather than passing in a ref in order to instantiate something:



I'm not sure if you know this, but the first value in a Type definition is the ID of the Type "object". I like my first variable to be a sprite ID or an integer that I manage on my own. This way I can sort all of my arrays. Also I ALWAYS do .insertsorted(var) on my arrays to allow me to use .find(var). I'm not sure what other people do, but this is what I like. I also never use dim which allows me to have arrays of dynamic size and that I can pass by reference and use the newer array functionality as outlined in http://www.appgamekit.com/documentation/guides/12_array_changes.htm.


EDIT: I didn't see that you had been a member since 2005, and I'm talking to you like you are a noob.... sorry.
make -C ../NagGaCreMo/2016 -f aGame.mk
dooz
19
Years of Service
User Offline
Joined: 22nd Sep 2005
Location:
Posted: 6th Jan 2016 00:27
no probs mrradd.

I am somewhat of a noob to AGK. I've had it since it was released, but haven't really put it through its paces because it had too many issues, particularly poor HTTP access, something I needed for a couple of apps.

Also, I'm a previously user of the Blitz pathway, BlitzBasic, BlitzMax. Then when I went to mobile I did native Obj-C / XCode / Cocos2D - most of my apps. Then when the Blitz folks released Monkey, I jumped on that - I have several apps out with Monkey.

So now I'm giving AppGameKit another crack - Tier 1. I did years of C++, but don't really want to go there again. Procedural functions is a bit of a mind flip, as Monkey has quite good OO and game frameworks too, however it gets clumsy at deployment time. I might still go back!

Regarding your post, I didn't know about the type object ID, however is that accessed, ID? As for the way you do you types, with CTOR's, and using arrays, I do it almost the same way - expect for the sorting, then is a good idea, as I wrote a hash map for this.

THANKS!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 6th Jan 2016 00:37
if you give a user defined type via ref to a function, a type in type should also be a reference not a copy.
its not a object or class, its just a struct. what you need is just the original and not a copy,
so by ref is ok, u not need a memory pointer.
i believe a problem is the = assignment, it will always copy a type.

AGK (Steam) V2.0.16 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 6th Jan 2016 22:51
Quote: "i believe a problem is the = assignment, it will always copy a type"

That's where I have run into issues, so I just manage the actual variable itself. If I have anything in an array, I always use the element which the value is stored.
make -C ../NagGaCreMo/2016 -f aGame.mk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 7th Jan 2016 00:00 Edited at: 7th Jan 2016 00:56
Quote: "That's where I have run into issues, so I just manage the actual variable itself. If I have anything in an array, I always use the element which the value is stored."

that is true but if you are performing a few operations on an array element you add the overhead of the array access for each operation.
the only alternative in these situations is to create a function to access the element or have a type defined and set it to the array element, do your work and then set the array element back to the defined type.
all a bit messy i think. a ref modifier for defined variables would be a much better solution
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 7th Jan 2016 01:06
I've toyed with the idea, and it would be nice to make the language more flexible, but it needs a lot of thought about the possible implications. Are there certain scenarios where a ref could end up pointing to invalid memory that need to be handled gracefully. For example pointing to an array inside a type that gets resized and therefore changes memory address. So not a high priority but something for the future.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 7th Jan 2016 03:04
you could get the same scenario when passing a reference. you could pass the ref into the function and that function could call another function which resizes the array (unwittingly).
for mine i would say that is the responsibility of the programmer and not having the functionality causes more headaches than having it would.
i know you have a much larger view of the product and at this point in time it doesn't fit in. :-(
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 7th Jan 2016 11:26
We have Tier2 for those who need the extra flexibility. Personally, I think BASIC should remain BASIC. I'm not a fan of making it just like C++.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 7th Jan 2016 12:49 Edited at: 7th Jan 2016 12:49
for the time being,my suggestion for the = assignment it would help to get smaller names and a better overview.
a as type
myarray as type[10]
a = ref myarray[i]
AGK (Steam) V2.0.16 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 7th Jan 2016 14:38
Thanks Markus for highlighting my point.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 7th Jan 2016 16:01 Edited at: 7th Jan 2016 16:02
Quote: "We have Tier2 for those who need the extra flexibility. Personally, I think BASIC should remain BASIC. I'm not a fan of making it just like C++. -CJB"

I totally agree. While declaring a ref would be nice, it would make the SCRIPTING language more convoluted. BASIC was written for a reason:
Quote: "In 1964, John G. Kemeny and Thomas E. Kurtz designed the original BASIC language at Dartmouth College in New Hampshire. They wanted to enable students in fields other than science and mathematics to use computers. At the time, nearly all use of computers required writing custom software, which was something only scientists and mathematicians tended to learn. Versions of BASIC became widespread on microcomputers in the mid-1970s and 1980s. Microcomputers usually shipped with BASIC, often in the machine's firmware. Having an easy-to-learn language on these early personal computers allowed small business owners, professionals, hobbyists, and consultants to develop custom software on computers they could afford. https://en.wikipedia.org/wiki/BASIC"

AGK's flavor has much more capability than original BASIC--maybe less than Visual BASIC--but it's a good interface. I think that was TGC's ideology behind it. I mainly bought AGK2 since there was a C++ back end and libs I could use. When using AGK2's BASIC you sacrifice OOP and flexibility for EXTREMELY FAST development or at least prototyping. Hell, I gave my friend a copy and he changed his major to CS

Sorry for the mini soap boxing.
make -C ../NagGaCreMo/2016 -f aGame.mk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 7th Jan 2016 21:00
Quote: "for the time being,my suggestion for the = assignment it would help to get smaller names and a better overview."

i couldn't agree more. if people don't want to use it then fine. i think not having it makes for a LOT more code than having it

Login to post a reply

Server time is: 2024-11-17 02:53:50
Your offset time is: 2024-11-17 02:53:50