Posted: 20th Sep 2011 15:24
Hello! I'm very new to AppGameKit and to programming, so please don't be too hard on me

Here is my code. I write a Menu Function, for easy creation of them. And right now there is my rock... working with files. This is a test.

It compiles good. But when i try to run it... it's crushing.
Help please. Is there some big mistake?
Thenks!

Here is the main code:
+ Code Snippet
TYPE MenuText
MenuEntry as integer
MenuName$ as string
EndType

GLOBAL DIM MenuEntryText[10] as MenuText
MenuEntryText[1].MenuEntry = 0
MenuEntryText[1].MenuName$ = "menu"
global line = 0
rem Portrait App
SetDisplayAspect( 0.66 )

MENU_TEXT()
rem A Wizard Did It!
do
 Sync()
loop



function MENU_TEXT()
opentoread(1, "test.txt")
for a = 1 to 10
MenuEntryText[a].MenuEntry = readinteger(1)
MenuEntryText[a].MenuName$ = readstring(1)
next a
closefile(1)

for b = 1 to 10
    MenuEntryText[b].MenuEntry = ((MenuEntryText[b].MenuEntry)+1)
    MenuEntryText[b].MenuName$ = MenuEntryText[b].MenuName$
next b

if MenuEntryText[b].MenuEntry > 0
for c = 1 to MenuEntryText[b].MenuEntry
CreateText (c, MenuEntryText[b].MenuName$)
SetTextSize (c, 24)
next c
endif
endfunction


And here is my test.txt:
+ Code Snippet
1 
START GAME 
2 
MAIN MENU 
3
INFO 
4 
WOW
5
TEST
Posted: 20th Sep 2011 17:45
I believe that you cannot read an integer or a string from a text file that you've created. Those must have been written by AppGameKit, and AppGameKit writes them in its own format.

To read in lines from a text file, use ReadLine(1) instead. That will read in each line as a string, and you can convert the string into an integer using Val(). Note that there is a bug with Val() where it only converts to integer, so you cannot use this technique with floats.

To use floats, you would need to switch back to ReadFloat(), but you would also need to have written the data into the file using AGK's notation.
Posted: 20th Sep 2011 18:51
Thanks for the answer! It helped. And other thing i finally realised what i did wrong in the code. )