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 / Got any C++ Beginners Advice for Tier 2?

Author
Message
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 15th Nov 2013 22:26
Hey Everyody,

Just raised my Kickstarter plegde for V2 and received V1. I'm very familiar with DBP code but always wanted to start with C++. I've got Visual C++ 2010 Express and compiled a few demos. I'm impressed!

Anyways, I'm a total n00b regarding C++ and the files and code does look different to me, so I'm wondering if there are any general C++ tutorials that you can suggest and if you have any other advice for me?

Thanks ahead!

Regards Sph!nx
www.mental-image.net
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 15th Nov 2013 23:15
All I can suggest is googling for intro C++ stuff.

Things to absolutely remember are that C++ is case sensitive. This applies to variables and functions and everything. So the variable named 'i' is not the same as the one named 'I'.

Another thing to watch out for is the use of '=' in logic operations. In AppGameKit Basic, you can say something like 'if a=b ...'. In C/C++, you need to do 'if (a==b) ...'. If you used 'a=b', what happens is that the variable a will get its value changed to whatever b is. If that happens to be a non-zero value, then it is considered true.

The template that comes with AppGameKit (I hope you installed v10819 and not v1076) gives you an idea of the basic structure.

Attached is a zip file full of code for a tutorial I am working on. It is meant to show how to use a state machine for dealing with some of the complications in Tier 2 and it also shows how to do HTTP communications and some other stuff. It might be a bit overwhelming, but it can show you how to work with AGK.

I just haven't been able to find the time to finish breaking up a very long web page into easier to handle chunks. Once I do, Paul will add it to the help system as a demonstration and the explanations for everything in the code will be there.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Attachments

Login to view attachments
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 16th Nov 2013 09:06
AL has some good advice there. A couple of other C++ tips when transitioning from BASIC.

If you want strings (ones that actually work like strings in BASIC), you need to do something like



Just put the first two lines at the top of your header files and then use strings to your heart's content. If you need to pass these strings into AppGameKit functions, just call



Also if you need dynamic arrays, you want vectors. These are used like



Hope that helps.

Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 16th Nov 2013 09:45
These are in codeblocks so I don't know how much value they will hold for you. If not feel free to ignore!

Here's a short video course I wrote on C a while back. C++ is an extension of that standard (it was originally known as C with Classes) it'll get you writing a couple of small programs quickly. It's not AppGameKit orientated but rather just C.

This is the first video in a 12 episode season. I'll produce more next year when I have the time!


This is the playlist for that course.
http://www.youtube.com/playlist?list=PLh2fPIBN1k1wO3JujafIjT8ddso9q_CbN

I also have some pure C++ videos but I didn't get very far into the season, because I wanted to do a C to C++ and then fork with C# and Objective-C. For overall information value the C course holds more at present.







Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 16th Nov 2013 16:13
Ohw, wow thanks guys (and lady)! Very much appreciated!

@ Ancient Lady
Yeah, It sure does look a bit overwhelming, but I can surely use that eventually. First I will need to start with something simple, like a stable 'main loop' and a few basic functions like drawing an image and stuff. Thanks!

@ Daniel
Great videos. I do hope you find the time for that series!

I've also found some good websites dedicated to C++. Here, for other who could use them:
http://www.cplusplus.com/doc/tutorial/
http://www.cppgameprogramming.com/cgi/nav.cgi?page=index.

I'm ready to dive in and plan to start with my own version of a 2D placement editor. Currently writing a to-do list!

I know C++ is now part of AppGameKit but I'm not sure if this board would be the place to ask general C++ questions, is it? I'm asking, because I'd rather ask my questions in this community than in other communities...

Regards Sph!nx
www.mental-image.net
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 16th Nov 2013 17:21
Sphinx, the 'main loop' in Tier 2 is the app::Loop() method in template.cpp.

You can do image loading and sprite creation anywhere. But the app::Begin() method is the best place to do your app initialisation (display mode, image load and sprite creation, etc.).

You can ask general C++ questions here as well. We are a supportive community. There are many of us here who have been programming for a long time.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 16th Nov 2013 17:38
One of the other things to be careful of with AppGameKit in Tier 2 is handling strings.

Anytime you get a string from some AppGameKit function, you need to remember to clean up afterwards. The strings are dynamically created on the heap and need to be deleted when done. Otherwise you are creating a memory leak that might come back to bite you in the butt.

Here is an example of how to properly handle a string returned from AppGameKit, using std::string (the best thing for doing string things):


The reason you don't simply directly assign the output of agk::Str() to a std::string is that the std::string makes a copy of the string assigned to it and does nothing with the source. It does not clean it up or store the pointer or anything.

This concept/issue is one of the things done in the tutorial whose code I posted further up this thread.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 16th Nov 2013 17:41
And, one of the reasons for doing a state machine in Tier 2 is because of how Sync() handling differs between Tier 1 and Tier 2.

In Tier 1, no matter where you call it, it will update all displays, user and device inputs.

In Tier 2, the user and device inputs are only update at the end (or beginning) of the app::Loop() method. Calling agk::Sync(); anywhere will always update display and physics. But only the one done (at the end preferably) of the app::Loop() method will make the user/device inputs available.

This was the original purpose behind the tutorial I put together. And then it grew a lot as I tried to make it a useful example.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 17th Nov 2013 13:59
Thanks, Ancient Lady, much appreciated. In DBP I always use one sync, at the end of the main loop. I will study what you gave very carefully to see what you did with the inputs.

Regards Sph!nx
www.mental-image.net
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 17th Nov 2013 16:17
I don't have any cases where I do any text input (that might be the topic of a different tutorial). But the way the buttons are handled shows a way to use the state machine for pointer inputs. That is also shown in the 'game' part of the code.

As long as I am around, I am happy to answer questions.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 17th Nov 2013 21:32
Thanks. You rule!

For now, I have plenty stuff to begin with to break my head on but I'll be surely back with more...

Regards Sph!nx
www.mental-image.net
Endless Mike
10
Years of Service
User Offline
Joined: 17th Sep 2013
Location: Connecticut, US
Posted: 18th Nov 2013 22:16
Quote: "Just raised my Kickstarter plegde for V2 and received V1"


Can I ask how this was accomplished?
I pledged at the standard backer level (aka wait for AppGameKit 2) - but I'm chomping at the bit to get a hold of something and would gladly give another £5 if I can get v1 to play with.
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 19th Nov 2013 13:44 Edited at: 19th Nov 2013 13:49
Sure mate. It's about 10 Pounds (I did 15 euros) from 25 to 35. I've contacted the support and asked if it was possible and it was.

- I transferred the money through PayPal to their PayPal account.
- Send email to Daniel (from TGC) with my personal info
- Send email to Christine (from TGC) to update badge

I'm pretty sure you can do the same, but It's best to contact the support before you do anything because I cannot speak for TGC.

Regards Sph!nx
www.mental-image.net
Endless Mike
10
Years of Service
User Offline
Joined: 17th Sep 2013
Location: Connecticut, US
Posted: 19th Nov 2013 17:26
appreciate it - thanks
joachim
12
Years of Service
User Offline
Joined: 21st Feb 2012
Location: Vancouver Canada
Posted: 19th Nov 2013 17:42
Thank you Ancient Lady.

I'm very happy to have found you're state machine tutorial.
This is the first time that I see how a professional programer
uses AGK.
Please continue with you're efforts to create tutorials,
because I can't even start to tell You how important and
helpful it is to actually see working code of this quality.

best regards,
Joachim
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 19th Nov 2013 18:20
You are welcome. I actually have an extensive write up that discusses all the things it demonstrates. It ended up being way too long for one page and I am way behind getting it broken up. When it is, it will appear somewhere in the on line documentation.

While working on it, it helped me tighten up some of the things in my own WIP (a peak has been posted).

My biggest 'failing' as a programmer is wanting things to be perfect. Sometimes too much time gets spent trying to get something 'just right'. And, in the case of web work, getting things aligned on the right pixels.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-05-20 13:18:41
Your offset time is: 2024-05-20 13:18:41