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 / Createtext with an array not working

Author
Message
AlexMes
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location:
Posted: 22nd Sep 2018 12:21
Dear forum,

I am not a novice to programming however I am new to AGK.

I am trying to create text with the input from an array, heres my code:



The code doesnt give any errors, the depth is also not a problem because when I replace the createText with CreateText (questionText, "Hello world" ) it will work fine.

I am probably making some kind of noob mistake thx
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 22nd Sep 2018 20:21 Edited at: 22nd Sep 2018 20:22
Hello! I think you forgot to describe what the problem actually is that you are encountering.

You said "The code doesnt give any errors, the depth is also not a problem because when I replace the createText with CreateText (questionText, "Hello world" ) it will work fine."
That's great but what is the behavior you are seeing if you do not make that change to the CreateText function?
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 22nd Sep 2018 20:38
That code works for me. Don't forget to resize the text with settextsize(). Default is tiny.
AlexMes
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location:
Posted: 23rd Sep 2018 11:32
Yes this code actually did work. But only if you run it all from the main.agc

When I declared the array questions as global in main.agc but then include a questions.agc in which i define the array. The array doesnt get populated.

So put the populating of the array in a seperate file, lets call it questions.agc:



and replace the upper code with this include line (inside main.agc)


Now the code doesnt work anymore.
puzzler2018
User Banned
Posted: 23rd Sep 2018 11:47
Quote: "You can use this command to simplify your main program by writing sub-programs that hold re-usable independent functions. The #include will associate all the functions within the sub-program with the main program during compilation. The filename string must specify an AGC source file in the current project directory.

Sub-programs can also use the #include command to further nest sub-programs, but all sub-programs compile into the main program so duplicated function names are not allowed.

Be aware that included source code is appended to the end of the program, so if you include any code that isn't part of a function it will be run if your main program reaches the end of its source code. There is no guarantee in what order the include files will be appended to the main program. As of AppGameKit version 2, global variables with default values, types, and arrays can be defined in sub programs and used in the main program, or in any other sub program.
"


Says to me that AGC (included files) store functions cause they are appended to the end of the main.agc - no matter where you put the #include

So all the types and questions setup wont take any affect whats ever cause its after the main.agc do/loop

Best to write all your types and questions setup at the beginning of the main.agc file and create functions in any #include files
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 23rd Sep 2018 11:54
Merely populating an array in an "included" file doesn't mean that the code lines will be executed. An include file is merely appended to the end of the main file. Within the included file you need to embrace the code you want to execute within a gosub or function, and then ensure that somewhere in the program you call the subroutine or function prior to the code that shows you the values. If you are using the "include" file merely to save space in the main program, and all it does is populate arrays with values, you might want to use the #insert directive rather than #include. That will effectively represent having the code where the #insert directive is placed, presumably ahead of the code which reports the values.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 23rd Sep 2018 17:28 Edited at: 23rd Sep 2018 17:33
Like they ^^^ said this is expected when using #include. As puzzler posted the key point here is Be aware that included source code is appended to the end of the program which means that included code is never being executed before trying to create a text object with the data.

Like Jeff said to get the behavior you are after use #insert instead of #include the docs say It is similar to #include except the code from the inserted file will be inserted into the main program at the location where #insert is called. In other words the #insert line will be replaced with the contents of the inserted file..
AlexMes
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location:
Posted: 26th Sep 2018 00:21
I see... got it
puzzler2018
User Banned
Posted: 26th Sep 2018 00:29 Edited at: 26th Sep 2018 00:30
that was a bit harsh wasnt it - as if you should have known

we are all still beginners and learning
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 26th Sep 2018 00:45 Edited at: 26th Sep 2018 00:57
Mine? Ah sorry maybe making the text large bold came across the wrong way. I was just doing that to emphasize the relevant bit no offense intended at all.
puzzler2018
User Banned
Posted: 26th Sep 2018 00:56
good man x
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 26th Sep 2018 00:57 Edited at: 26th Sep 2018 00:58
Honestly I only noticed you guys had already answered after writing it all so then added in the bits about puzzler and jeff. Or maybe saw yours but not Jeff's yet. Something like that. Be nice if we could delete our dang posts and when things like that happen be a 1-click fix. Lol
puzzler2018
User Banned
Posted: 26th Sep 2018 00:59 Edited at: 26th Sep 2018 01:02
Its ok honest dont worry about it. - i find caps or anything bigger font is over powering thats all - cause thats all people aim towards - an Upper sign - only natural for any human

it states to me your shouting at us lol

GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 26th Sep 2018 01:18 Edited at: 26th Sep 2018 01:19
LOL! Never do that. It is just styling and emphasis to make skimming to the main bits easier. I wish everyone did that. Some folks do put a TLDR on posts maybe not here I guess but elsewhere is common. I just kind of highlight the key stuff so is more efficient.

Well I am glad we had this discussion.
puzzler2018
User Banned
Posted: 26th Sep 2018 01:21
its ok honest, keep up good work

Login to post a reply

Server time is: 2024-04-18 23:24:38
Your offset time is: 2024-04-18 23:24:38