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 / [bug] #include(s) and Dim XXX[ YYY ]

Author
Message
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 1st Mar 2016 14:50
Hello.

I'm creating some sort of "modules" for my devs.
So I need to create data (global) that will be defined inside the #include as startup.

If I create data like inside my #include(d) file :
global mydat = 5
it work.

But if I try to create dim data, even if I put global before .. it don't work.
Compilation is ok but running the app will produce an error message pointing to an "empty data".
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Mar 2016 15:30
i remember the include add the content at the end of the main source file.
maybe try insert instead
#insert
#include
AGK (Steam) V2.0.17 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 1st Mar 2016 18:18
Thank you Markus, I will try this now
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 1st Mar 2016 23:48 Edited at: 1st Mar 2016 23:54
you CAN #include files that declare their own data, i do it all the time as I LOVE self declaring modules!

For example, I'll declare a function like this...

Global Variable = 5 will work at the top of an included file without being executed past, Dimming variables HAS to be executed, so needs to be within a function. (DIM has been depreciated in favour of the new style of declaring variables, as I've used in my snippit. )
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 2nd Mar 2016 08:58
If you use #include it will add your code to the bottom like Markus said. DIM is not really a data declaration and you need to run through that code during runtime. A global declaration is handled before runtime and will always work regardless of where it's placed.

Try this instead:
Global myArray as integer[5]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Mar 2016 10:05
I always include an Init() in my modules, e.g...

initEffects()

It is a neater way to ensure your module is initialised with basic data, and only when you call it.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Mar 2016 11:16
normal define something global inside a function is at a wrong scope but it works in agk.
AGK (Steam) V2.0.17 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 2nd Mar 2016 17:15
In AppGameKit globals are always defined before the program starts, regardless of where they are. Even if you put them inside a function that you don't call. The compiler takes care of that.

Login to post a reply

Server time is: 2024-11-25 10:26:08
Your offset time is: 2024-11-25 10:26:08