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 / Where are the Dynamic Types?

Author
Message
Alien Menace
AGK Developer
19
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 16th Oct 2011 06:08
Using arrays to manage players, enemies, bullets, etc. is a practice that should have died about 10 years ago. Where is the FOR.. EACH, DELETE and ADD/PUSH commands?

GLBasic has them, why doesn't AppGameKit?

Intel i7-2600k - Asus P67 Sabertooth - 16GB RAM - 2x GTX 460 OC SLI - Lexar 128GB SSD Drive - 2TB ATA/600, Windows 7 x64. iPad, iPad2, iPhone 3GS & 4, HTC Inspire, Mac-Mini. Apps published: 1
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 18th Oct 2011 02:14
AGK T1 (BASIC) is a great language for learning the core lessons of programming and rapid development but for those coders looking for modern techniques you best choice is T2 (C++) which offers everything from class structures to pointers. Rather than try to squeeze lots of advanced approaches into BASIC, or dumbing down C++, we decided to offer two flavours, to give each group the best chance based on what they are after.

We could still add dynamic data structures to the AppGameKit compiler, but we need to sit down and really plot out the best way to do it that compliments the existing AppGameKit command set. The danger is that by dropping in lots of alternative approaches to the problem of data management, we have a language that takes longer to learn and master. I often ask the question, what is it that you actually want to achieve which the current system cannot handle. It's a great starting point when discussing new additions to the language.

I drink tea, and in my spare time I write software.
XanthorXIII
AGK Gold Backer
13
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 18th Oct 2011 16:38
While GLBasic may have it, it's missing several things that AppGameKit has going for it. Particles, Box2D, Easier Sprite Manipulation etc...
Granted I would like to see a FOR/EACH, DELETE, ADD/PUSH added to AppGameKit as well, but given that it's a newer language may take a little bit for it to get implemented.
As Lee stated, adding too many commands can confuse people. Better to keep it simple at the moment.
MobileCreator
13
Years of Service
User Offline
Joined: 1st Jun 2011
Location: Ottawa - Canada
Posted: 18th Oct 2011 23:32
As for language simplicity, I believe using For/Each to manipulate lists of objects instead of static arrays is way easier to learn, so if the idea is make the tier 1 Basic easy to learn, these would be nice additions to accomplish that.

For old school developer like me, who actually learn Basic as first language back in 1832, using static arrays are very natural, but some adding some modern commands would help a lot make the logic simpler.

Cheers

----------
Paulo
http://www.mobilecreators.com
Alien Menace
AGK Developer
19
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 19th Oct 2011 09:05
You make some excellent points Lee and I understand your concerns. I'd like to offer my two cents worth on the subject.

I don't think you have to make the rather large leap from Basic to C++ just to get the benefit of something like dynamic types. I feel dynamic types have become a modern Basic concept that is included in several other Basic-based languages similar to AGK. I agree that you don't want to move fully into some kind of Basic/C++ extreme hybrid (which others have done) but simplifying the management of players/enemies/bullets/etc in any game development environment should be a priority and I think it is very implementable within Tier-1. As far as Tier-1 being a beginner's language, well I can't think of many 2D games in the appstore that could not be written using Tier-1.

For example, I would prefer to manage my types this way:

ForEach bullet in bullet
ForEach ship in ships
if GetSpriteCollision( bullet.id, ship.id)
PlaySound(ship.sound)
Inc Score, ship.value
Delete ship
Delete bullet
endif
Next
Next

For one thing, this is faster than having to run through the entire length of both fixed arrays because there COULD be data in there. Another situation is when you spawn an enemy or a bullet, you don't have to run through the array to locate the first empty record in the array to create your new object. Also, being able to simply delete the type when you are finished with it is pretty darn awesome. I can't tell from the help file how you clear the data from an array record now without writing a null value to all the typed objects.

Simply stated, I think as is, handling enemies, ships, bullets, etc is more cumbersome than it needs to be. In my opinion, this is pretty easy stuff to learn and makes managing your objects a breeze. For people that don't want to learn to use these or don't like them then they have the options of sticking with arrays. I intended to switch over to AppGameKit for GLB but I suppose I am spoiled and it's tough for me to "set my watch back" to old school arrays.

Thanks.

Intel i7-2600k - Asus P67 Sabertooth - 16GB RAM - 2x GTX 460 OC SLI - Lexar 128GB SSD Drive - 2TB ATA/600, Windows 7 x64. iPad, iPad2, iPhone 3GS & 4, HTC Inspire, Mac-Mini. Apps published: 1
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 19th Oct 2011 10:51
It's perfectly possible to create a linked list inside a static array. The only problem is that it needs to be dimensioned to some adequate length before using it.

-- Jim
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 23rd Oct 2011 03:50
@Alien Menace : You make a good case for FOR EACH. Post exactly how it would look in AppGameKit and we can work from there. Take the example of a bullet being fired, managed and destroyed as that often deals with a very dynamic list of objects during the game.

I drink tea, and in my spare time I write software.
Alien Menace
AGK Developer
19
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 25th Oct 2011 22:28 Edited at: 25th Oct 2011 22:46
Here ya go..



Thank you.

Intel i7-2600k - Asus P67 Sabertooth - 16GB RAM - 2x GTX 460 OC SLI - Lexar 128GB SSD Drive - 2TB ATA/600, Windows 7 x64. iPad, iPad2, iPhone 3GS & 4, HTC Inspire, Mac-Mini. Apps published: 1
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Oct 2011 01:12
As the idea behind Basic is to make commands obvious I would suggest "EndAdd" rather than "Push dataType"... I don't know what "Push" means from reading it. It fits in better with the language to me.

I like the idea of Dynamic Types a lot as it would simplify a lot of my code. I agree it fits in well with the language.

Just a 'Basic' programmer's perspective.

Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 26th Oct 2011 02:34
My only problem with that example is, what if you want more than one list? That groups all instances of the type together.

In C#, the foreach syntax is (simply put):

foreach(Type item in container)
{ <block> }

The container is any class that supports enumeration, such as a list or array. For AppGameKit I would think something like this would be nice:



I wouldn't be 100% set on my syntax there (pseudo code is difficult on an iPad) but I think containers need to be independent from the type itself and the syntax should be consistent with the rest of the language.
Alien Menace
AGK Developer
19
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 26th Oct 2011 03:15 Edited at: 26th Oct 2011 03:31
@baxslash - Basically that is just saying that you are ready to push this object to the list. It makes more sense to me that way but I really don't care what the command is. The easier the better.

@Airslide - I originally suggested that method in my pseudo code a few posts above. In the example, I am obviously trying to keep the concept as simple as possible taking into account Lee's concerns. I assume Lee is a C++ programmer and probably already knows how it's done in that language.

Being able to have the system manage multiple lists offers more flexibility but for me, not an absolute deal-breaker as I can create multiple Type templates if I really needed to. You sort of run into that question of how to implement a powerful feature like this while keeping in mind that person who just picked up AppGameKit for the first time. I'm not advocating turning AppGameKit into a OOP language, I just want an easier way to manage my game assets than what is currently available. Dynamic Types in whatever incarnation they come in will certainly help.

Also as Lee mentioned, if you want the full meal deal there is always the Tier-2 option.

Intel i7-2600k - Asus P67 Sabertooth - 16GB RAM - 2x GTX 460 OC SLI - Lexar 128GB SSD Drive - 2TB ATA/600, Windows 7 x64. iPad, iPad2, iPhone 3GS & 4, HTC Inspire, Mac-Mini. Apps published: 1
Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 26th Oct 2011 05:54
Personally I don't think it'd be too complicated, in fact having a list that they created could make it easier for a new user to grasp where their data is being stored. As it is right now they have to learn arrays, and lists seem a little more natural even.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 26th Oct 2011 12:37
I use Delphi all the time because I dislike C++. Delphi's iteration is very powerful and simple, and can work with almost any list type. It's implemented using the already existing keyword "in".

Here's a string example:
var
s: string;
c: char;

begin
s:=' Delphi Rocks!';
for c in s do //<--- here is the interesting part
begin
Application.MainForm.Caption:=Application.MainForm.Caption+c;
Sleep(400); //delay a little to see how it works
end;

Also works with dynamic lists, and easy to understand because it's just a special case of a for loop.

-- Jim
Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 27th Oct 2011 01:23
The problem I'm seeing for a foreach keyword though is that even in my example it looks dangerously close to using reference types. It could be confusing to users when their variables don't act the same way outside the loop.
Alien Menace
AGK Developer
19
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 27th Oct 2011 07:01
Not sure I follow...

Intel i7-2600k - Asus P67 Sabertooth - 16GB RAM - 2x GTX 460 OC SLI - Lexar 128GB SSD Drive - 2TB ATA/600, Windows 7 x64. iPad, iPad2, iPhone 3GS & 4, HTC Inspire, Mac-Mini. Apps published: 1
Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 28th Oct 2011 02:27 Edited at: 28th Oct 2011 02:28
Understandable, I didn't really elaborate. Basically, the variable for the item in the foreach loop ("current" in my example) is a reference back to the element inside the array (bullet[current's index]). This doesn't really match up with the rest of the language. For example:



That example should make perfect sense, since UDTs are essentially structs. When var2 is assigned to var1, var1's values are copied into var2, it does not become a pointer. If they were reference types:



Now, the problem here is that the current item in the foreach loop looks a lot like that sort of reference. So somebody might be tempted to do this:



However, that won't work. 'bullet' in the foreach loop is a reference/pointer type to bullets['bullet''s index]. However, when we pass it as a parameter, we are just copying it into 'obj'. So we need the index in order to act on bullet in another scope, such as that of a function. This may be confusing and, for a large project, makes foreach more of a convenience for loops that are entirely self contained than something that can be used for entity management.

If the foreach loop treats the item variable like the rest of the language treats UDTs, then any modifications you make to it won't be saved back to the array, which diminishes its value a bit (but would be in line with how foreach on an array of structs works in C#).
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 28th Oct 2011 14:22
I agree with airslide about this, but it's not an inherently difficult problem to solve. It's very simple and obvious in Pascal and C and has been for 30 years. All it needs is a pass by reference flag:

procedure NoRef(x : integer)
begin
// x is copied to this function and becomes a local variable
x:= x + 1; //increases the local variable but NOT the passed variable
end;

procedure ref(var x : integer)
begin
// x must be an actual variable, not a constant
x := x + 1; // the variable passed in x is changed
end;

With object orientation things become slightly muddied, because objects are always passed as dynamic and modifiable.

Hey ho!

-- Jim
Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 30th Oct 2011 05:11
The ref flag idea is a good one in my opinion, but Lee has previously expressed apprehension about pointers and reference types. Still, an explicit "ref" keyword seems easy enough to follow.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 30th Oct 2011 10:57
I agree. There's a significant difference between passing by reference and allowing an explicit pointer type which could be modified to point outside the sandbox. One advantage is that it removes the need for loads of global variables, which are regarded as bad programming practice.

-- Jim
Jimmy 9Toes
15
Years of Service
User Offline
Joined: 24th Nov 2008
Location:
Posted: 21st Nov 2011 20:19 Edited at: 21st Nov 2011 20:22
Monkey has dynamic lists



AGK could do something like that (imho)

Yes THEE Jimmy9Toes
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 23rd Nov 2011 04:18
I think Lee would probably like to avoid adding reference types, etc. to the language. A much simpler change could be to allow things like this:



It only introduces one keyword ("in <array>") which translates directly into "= 0 to <length of array>" and doesn't require changes to the AppGameKit player.

The next thing that is definitely needed is the "continue" and "redo" commands to complement the "exit" command. "continue" should jump to the next iteration of a loop. "redo" should jump to the start of the current iteration.

"continue" allows you to skip a loop without having loads of nested if statements:


"redo" allows you to easily delete from an array while looping through it:


[b]
Euphoria
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: United Kingdom
Posted: 23rd Nov 2011 17:46
I agree with Diggsey and understand the issue Airslide raises. IMO the foreach should return the index of the array it is iterating as oppose to a reference or copy of the actual element. So Airslides example would become:



Save the confusion of passing by reference.

Dynamic arrays should be high on the list (With Push/Pop/size functions) to....I would say associative arrays would be nice but maybe thats just a personal love of mine
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Nov 2011 10:47
I can do without associative arrays, but dynamics arrays is a must. It's hard to write my xml parser without them.

"You're not going crazy. You're going sane in a crazy world!" ~Tick

Login to post a reply

Server time is: 2024-11-22 14:43:28
Your offset time is: 2024-11-22 14:43:28