DATA statements?

Previous topic - Next topic

AndyH

Same here... this error for me, but makes no sense (not changed my code):

Code (glbasic) Select
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.2008.072 - 3D, NET
Wordcount:1159 commands

compiling:
C:\Users\AndyH\AppData\Local\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::LoadLanguageStrings()':
C:\Users\AndyH\AppData\Local\Temp\glbasic\gpc_temp0.cpp:1286: error: `LINE' was not declared in this scope
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Time: 6.1 sec
Build: 0 succeeded
*** 1 FAILED ***
Also notice two new fields in the project settings cmp and lnk which I'd not seen before.  What are they for?

Reverted back to build 198 and it runs fine (yay for the backups!).

Kitty Hello

AH!!!! You have to define a LOCAL for the variables you're reading. I'll fix that!

PeeJay

Oooh, can this be changed? After all, it is entirely possible you want to read a value into a GLOBAL variable .....
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Kitty Hello

It's already fixed. Get an update, sleepy head! ;)

AndyH

Thanks Gernot :)

PeeJay

Thanks hugely - works a treat now :)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

AndyH

Can't thank you for how much easier it is to set up some simple tables of data now. Thanks for this.

Could I possibly ask one more tiny enhancement...


Could you allow an offset to added to the RESTORE label command.  eg:

Code (glbasic) Select
RESTORE scoreValueList  // this points the READ at the start
READ val // returns 1

RESTORE scoreValueList + 5 // this skips ahead 5 DATA values
READ val // returns 6

STARTDATA scoreValueList:
DATA 1,2,3,4,5,6,7,8,9
ENDDATA

PeeJay

If we're going for non-standard enhancements, being able to resore to a variable string would be incredibly useful - for example:
Code (glbasic) Select
LOCAL d$="LEVEL"+lev
RESTORE d$

STARTDATA LEVEL1:
DATA 1,2,3
ENDDATA

STARTDATA LEVEL2:
DATA 3,4,5
ENDDATA

STARTDATA LEVEL3:
DATA 6,7,8
ENDDATA

etc
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

AndyH

Good idea Peejay.  It's not actually a totally non-standard way as I used a BASIC in the past where you could do this.  I guess you could do your level trick without the extra labels using the offset,

eg:

GLOBAL offset = (level-1) * sizeOfLevel

RESTORE LEVELS + offset

Hey Gernot, if RESTORE label+offset is too wierd for the language, something like this could work also :   RESTORETO label, offset

PeeJay

You could do it with the offset in the example I gave, but only if all the levels held the same amount of data. Since I have a habit of having a continual loop until reaching a termination flag, it wouldn't then work - for example:
Code (glbasic) Select
LOCAL d$="LEVEL"+lev
RESTORE d$

WHILE TRUE
 READ b
 IF b<>-1
  //do something
 ELSE
  BREAK
 ENDIF
WEND

STARTDATA LEVEL1:
DATA 1,2,3,-1
ENDDATA

STARTDATA LEVEL2:
DATA 3,4,5,-1
ENDDATA

STARTDATA LEVEL3:
DATA 6,7,8,9,10,11,12,-1
ENDDATA

etc
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

AndyH

True, and I still think your suggestion is a very good idea.  Just thinking about other ways too.  I guess you could always have another Data block to index your start positions, or an array, but I guess that's just making more GLB runtime code that could perhaps be done simpler if GLB natively supported what you wanted anyway.

Wild_Duck

When I tried to use Data statements at the "StartData label:" I get a syntax error. It changes to the command colour after typing it but to white after compiling it.

Kitty Hello

How about:
Code (glbasic) Select
STARTDATA common:
 data 1,2,3
ENDDATA
STARTDATA special:
   DATA 1,2,3
ENDDATA

RESTORE common
ReadCommon()
RESTORE special
ReadSpecial()?
Or make your own "SkipData: n" function.

AndyH

The only problem with making a skip data function would be the need to sequentially read through n number of data statements before you could get to the right point.

I was thinking a RESTORETO command would allow me to treat the DATA as static memory, so I could grab data from any point within (from the offset) quickly without the need to load the DATA into another format (membanks or array) in order to do that.

Minion

Help !

I have no idea why, but I`m getting an error when I set up my data statement.

Code (glbasic) Select

STARTDATA dataitems:
DATA 1,"PLAY    ",-1,0,0
DATA 1,"OPTIONS ", 2,0,0
DATA 1,"QUIT    ",-2,0,0
DATA 2,"LEVEL   ", 3,0,0
DATA 2,"VOLUME  ", 4,0,0
DATA 2,"BACKDROP", 5,0,0
DATA 2,"BACK    ", 1,0,0
DATA 3,"EASY    ", 2,1,0
DATA 3,"MEDIUM  ", 2,1,1
DATA 3 "HARD    ", 2,1,2
DATA 4,"100%    ", 2,2,100
DATA 4," 75%    ", 2,2,75
DATA 4," 50%    ", 2,2,50
DATA 4," 25%    ", 2,2,25
DATA 4,"  0%    ", 2,2,0
DATA 5,"ON      ", 2,3,0
DATA 5,"OFF     ", 2,3,1
ENDDATA


Thats the code, but it just throws up a syntax error at the STARTDATA statement, and for the life of me I cant see why ;( Am I missing something trivial ?