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 / Running a separate code file? And code organization?

Author
Message
Tobias_Ripper
11
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 14th Nov 2015 19:36
Hey, everyone.

It's been a few years since I've engaged with tgc forums, feels great to be back on familiar grounds. I've owned AppGameKit for quite a bit now but never really had much of a need to explore it since I had a load of other 2d engines I've used for years. Until now when I need a powerful lightweight 3d engine.

When you use a "do loop" you get that while loop in a nice bracket located in the line number label column to the left of the editor. This is very useful for keeping the code in manageable blocks which you can just minimize and maximize to your comfort. It's this feature possible to set up with any piece of selected code? Or is it strictly limited to "do loop" and for loops?

Second question is partially regarding the same topic. I'm setting up my 3D world with a randomly generated terrain. The code will get pretty big but it's only run once. I noticed that you are ale to create more files that are a part of your project. Would I be able to create a separate code file with my game set up fictions and execute that file from within the main game file?
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Nov 2015 20:55
code folding
foldstart
foldend

make new file from menu and in main include it
#include "game.agc"
#include "manual.agc"

AGK (Steam) V2.0.15c : Windows 10 Pro 64 Bit : AMD (15.201.1151.0) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Tobias_Ripper
11
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 15th Nov 2015 04:15
Ah, perfect.

That set me on the right place/
I used #insert instead from the same help page since it executed the code as it inserted the file.

Thank you.
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Nov 2015 13:14
yo, include append the main file, so insert is better.
AGK (Steam) V2.0.15c : Windows 10 Pro 64 Bit : AMD (15.201.1151.0) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Tobias_Ripper
11
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 15th Nov 2015 21:09
When the #include appends the file that ran the function, how do you return back to the main file when the code in the included file has run its course? Just #include main file in the end with the second file to return?
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Nov 2015 22:37 Edited at: 15th Nov 2015 22:38
the normal flow:

MainLoop()
End

function MainLoop()

do
if ... then exit
sync()
loop

endfunction

without functions from top level u can jump around with goto or gosub.
its also possible to jump inside a function.
from inside a function u can all other functions, similar the commands u are called.
http://www.appgamekit.com/documentation/language/22_gosub.htm
AGK (Steam) V2.0.15c : Windows 10 Pro 64 Bit : AMD (15.201.1151.0) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Tobias_Ripper
11
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 16th Nov 2015 01:29
Ah that's where those were.
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 17th Nov 2015 03:35
You definitely do NOT include the main in the included file.

Using gosub from the main file to an included file is not a great idea. But it is doable. If you use gosub, you MUST use 'return' when exiting the sub. Otherwise you seriously mess up the call stack.

I highly recommend using functions instead of subs. Using goto should be done only as a last resort.

Using functions allows a clean encapsulation.
Cheers,
Ancient Lady
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 17th Nov 2015 15:38
I have declarations and functions in external files. I then include them at the top of my main file. I can then call these functions when needed. IIRC you can't have the program run into function declarations so they must always be after your main loop. I also don't have my main loop in a function but at the end of my main file.

Login to post a reply

Server time is: 2024-11-17 00:50:19
Your offset time is: 2024-11-17 00:50:19