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 / Why doesnt AGK like my types? :(

Author
Message
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 27th Mar 2014 17:36 Edited at: 27th Mar 2014 17:48
SOLVED!
Hello!

Basically I'm trying to create an array for storing information about a level in a game... And AppGameKit refuses to let me!

Here's what Im working with:


And the error:

(the code is placed in levelbuilder.agc and "#Include":d in the main.agc)

Now, line 12 is this:
... What am I doing wrong?
I've tried changing names on all the variables, but to no avail.

All help appreciated!
Thanks!

nope.

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 27th Mar 2014 17:39
I think it's just that AppGameKit doesn't like to declare types inside functions, this should work...



I am the one who knocks...
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 27th Mar 2014 17:41
Thanks for the quick reply... That seems to have done the trick!

One more question though, when you place code outside a function or sub in an included file, when does it execute?

nope.

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 27th Mar 2014 17:45
Well when it's in an included file, I'd always put the declerations in a subroutine, then call the subroutine from the main code, like an init procedure.
Anything outside of a procedure or function is ignored in an included file (I'm sure, might be wrong on that) - so it's usually best to have an init routine and functions as a rule.

I am the one who knocks...
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 27th Mar 2014 17:48
Thanks!

nope.

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 27th Mar 2014 18:27
You do not have to put in type and global declarations in subroutines. Possibly you have to consider the order of your #include lines but I have not tested that as I declare my types and globals separately for each file as needed.

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 27th Mar 2014 19:25
I keep forgetting that, it just seems... well kinda weird to just have a type declaration in the root of a code file. I mean, when and where does it get added to the main source, at the end?, at the start?... or are type dec's handled separately?

I think having a type declaration in a sub file outside of an init routine is the work of the devil... bad mojo... no good can come of meddling with supernatural coding like that!
To me, that's code limbo - just sitting there in no particular function or subroutine... why doesn't that feel wrong to everyone else!

I am the one who knocks...
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 27th Mar 2014 20:10
Quote: "when and where does it get added to the main source"


I would guess at the end of the main file. To me it just makes perfect sense to have all my declarations at the top of the file that needs them. If you make a file with useful functions with declarations then all you have to do is include that one file.

My files only contains declarations and functions and I have a do-loop in my main file. No GOTO or GOSUB. RTA is not a small project, 21 files. And not a single error.

easter bunny
12
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 29th Mar 2014 07:01
I do it like this:

Main.agc


init.agc



Yes, it uses the dreaded gosub, but is it really that bad? It's working exactly the same way as if they were in the root of main, but the code is much cleaner

Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 29th Mar 2014 18:41 Edited at: 29th Mar 2014 18:42
AGK is good, you don't even need to execute a type definition for it to occur.

I declare my type like this.

Quote: "Main.agc

#include types.agc
dim MyType[ 0 ] as tMyType
end
"

.
Quote: "Types.Agc

Type tMyType
EndType"


I like all my code to be self declaring, so all types in include files are declared at the top of the file, NOT in any functions.

Then when I call a function the first time, if it hasn't been declared it'll automatically call the declaration function which will do all the DIMing and GLOBALing.

This way, all my AppGameKit includes are plug and play. An example is my UI engine. All I need to do is #include UI.agk and it's all setup. As long as my main loop calls UI_Update() I don't need to explicitly do any initialisations.
Any include file which has dependencies for other files will #include them itself.

My current game engine is structured so that the game is in one folder, and the core engine files are in another. In my Game, I'll #include ..\Engine\Engine.Agc and that's it.
Game specific files remain in the game folder, engine specific files stay in its own folder. I can update the engine independently of the game, and vice versa.

Login to post a reply

Server time is: 2024-11-25 03:57:21
Your offset time is: 2024-11-25 03:57:21