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.

Newcomers AppGameKit Corner / Can you reference a type without passing it via a function?

Author
Message
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 17th Jul 2017 22:45

setup:


I can do this:


But can i do this? - ref the Type object by a temp var without passing it via the function argument?
From what I understand below I am making a copy of the object ("self")and changing those values rather then the source object ("player1") values


blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th Jul 2017 23:09 Edited at: 17th Jul 2017 23:09
Your logic (re: making a copy of the object) is correct. You could always return the type like this


then you could call it like this
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 18th Jul 2017 08:32
Understood, so there is no equivalent to 'ref' that can be used to 'reference' or 'point to' an existing Type object outside of a function argument?

It's not game breaking but would be a 'nice to have', currently covering some of my framework from Blitzmax and I make use of 'pointers' (I think that's the correct terminology) for readability.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 18th Jul 2017 08:37
No unfortunately. This has been discussed and unfortunately TGC don't see it as a functionality they want to add to the product. Maybe you could request it in the feature requests thread so they know people want it.
Supertino
6
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 18th Jul 2017 09:17 Edited at: 18th Jul 2017 09:18
[quote=No unfortunately. This has been discussed and unfortunately TGC don't see it as a functionality they want to add to the product. Maybe you could request it in the feature requests thread so they know people want it.] <---- I dont know ow this quote think works.

Thanks I might just do that, I have a few other 'features' i miss too, I do have to remind myself I am coming from a much more OOP language though so have to manage my expectations accordingly.
MikeHart
AGK Bronze Backer
20
Years of Service
User Offline
Joined: 9th Jun 2003
Location:
Posted: 18th Jul 2017 15:05
Hi supertino. What I did was storing the type in an array and referencing it with its index.
Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200. Using AGK2 Tier 1.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Jul 2017 00:21
The problem with not having a ref is exactly that with arrays.
With a ref you can set the value to the array element and then work with the ref and not worry about the index.
What you have to do now is move the array element into the type, work on the type and then move it back to the array.
When you have multiple exit points you have to remember to move the type back into the array. If you forget it is a very difficult bug to find.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 25th Jul 2017 15:15
Quote: "With a ref you can set the value to the array element and then work with the ref and not worry about the index."


yes that's something I like to do, its tidier and more practical.

a small example for anyone wondering the difference


Login to post a reply

Server time is: 2024-03-28 11:33:34
Your offset time is: 2024-03-28 11:33:34