How To

Too many tokens error

0

AnthonyJean 2020-04-12 04:11

I’m getting a too many tokens error. Anyone help with this? Thanks...


was8bit 2020-04-12 05:13

You need to economize your code... you do not have unlimited size to work with....


was8bit 2020-04-12 05:16

For example...

IF MG=1 THEN MONN$="BLACK ORC"
IF MG=2 THEN MONN$="HOBGOBLIN"
IF MG=3 THEN MONN$="GIANT WASP"
IF MG=4 THEN MONN$="BLOODY TOAD"
IF MG=5 THEN MONN$="POISON OOZE"
IF MG=6 THEN MONN$="GREY SNAKE"
IF MG=7 THEN MONN$="TIMBERWOLF"
IF MG=8 THEN MONN$="GIANT RAT"
IF MG=9 THEN MONN$="RED GOBLIN"
IF MG=10 THEN MONN$="GREEN SLIME"
IF MG=11 THEN MONN$="BLUE SLIME"
IF MG=12 THEN MONN$="PIT VIPER"
IF MG=13 THEN MONN$="GIANT ROACH"
IF MG=14 THEN MONN$="WHITE WIZARD"
IF MG=15 THEN MONN$="RABID DOG"
IF MG=16 THEN MONN$="WILD BOAR"
IF MG=17 THEN MONN$="HUNGRY LION"
IF MG=18 THEN MONN$="ZOMBIE QUEEN"
IF MG=19 THEN MONN$="DEMON HOUND"
IF MG=20 THEN MONN$="EVIL WYVERN"
IF MG=21 THEN MONN$="SNEAK THIEF"
IF MG=22 THEN MONN$="ICE GIANT"
IF MG=23 THEN MONN$="VIKING LORD"
IF MG=24 THEN MONN$="EVIL SPIRIT"
IF MG=25 THEN MONN$="DEMON SPAWN"
IF MG=26 THEN MONN$="RING WRAITH"
IF MG=27 THEN MONN$="MINOTAUR"
IF MG=28 THEN MONN$="GOLD DRAGON"
IF MG=29 THEN MONN$="DARK ELF"
IF MG=30 THEN MONN$="RED HELLBAT"
IF MG=31 THEN MONN$="ANGRY TROLL"
IF MG=32 THEN MONN$="ANGRY DWARF"
IF MG=33 THEN MONN$="WOOD TROLL"
IF MG=34 THEN MONN$="DARK WIZARD"
IF MG=35 THEN MONN$="WOOD ELF"
IF MG=36 THEN MONN$="DOPPLEGANGER"
IF MG=37 THEN MONN$="DARK ANGEL"

Could be simplified with

DIM MONSTER$(37)
FOR I=1 TO 37
READ MONSTER$(I)
NEXT I
DATA "BLACK ORC","HOBGOBLIN"
...
DATA "DOPPLEGANGER","DARK ANGLE"

Then simply use MONN$=MONSTER$(MG)


was8bit 2020-04-12 05:19

IF OI$="Y"THEN SOUNDPLAY=1
IF OI$="Y"THEN SOUND SOURCE ROM(15)
IF OI$="Y"THEN MUSIC 8
IF OI$="Y"THEN SOUND SOURCE ROM(14)
IF OI$="Y"THEN GOTO HARDWAREGO

Can be simplified with

IF OI$="Y" THEN
SOUNDPLAY=1
SOUND SOURCE ROM(15)
MUSIC 8
SOUND SOURCE ROM(14)
GOTO HARDWAREGO
END IF


was8bit 2020-04-12 05:23

CLS
PRINT
PRINT
PRINT
PRINT
PRINT " YOU HIT THE"
PRINT
PRINT " ";MONN$
PRINT
PRINT

Can be simplified with
CLS
TEXT 4,2,"YOU HIT THE"
TEXT 6,3,MONN$


was8bit 2020-04-12 05:27 (Edited)

You need to STANDARDIZE things like

PRINT " ACTIONS:"
PRINT " (L)OOK (T)ALK"
PRINT " (U)SE (R)EAD"
PRINT " (N)ORTH (W)EST"
PRINT " (I)NVENTORY"
PRINT " (Q)UIT"

Make them more standardized, and use SUB so you can reuse the commands...this would eliminate a ton of repeated code...


was8bit 2020-04-12 05:45

You also could use an array like
DIM ROOM$(99,99)

And maybe use a coded system that defines each room.. as
$code="NSEWUDMMII
Which means can go North,South,East,West,Up,Down, Monster, Item

So ROOM$(0,0)="1100001206"
Would mean, can go north or south, has monster 12 and item 6
N$=MID$(ROOM$(0,0),1,1)
S$=MID$(ROOM$(0,0),2,1)
E$=MID$(ROOM$(0,0),3,1)
W$=MID$(ROOM$(0,0),4,1)
U$=MID$(ROOM$(0,0),5,1)
D$=MID$(ROOM$(0,0),6,1)
Mon=VAL(MID$(ROOM$(0,0),7,2))
Item=VAL(MID$(ROOM$(0,0),9,2))


was8bit 2020-04-12 05:46

Coded arrays would remove all the code typed in for EACH room, and would rather use a loop that handled ANY room based on the room settings...


was8bit 2020-04-12 05:50

Alternatively, if you prefer your style of coding, you will need to break down your game into smaller "chapters" and restrict each chapter to fit lowres without getting the token error...

You can use in-game passwords to restrict players from playing one chapter until they complete the previous chapter :)


Timo 2020-04-12 13:57

Yes, a NX program is limited to 16384 tokens. A token is something like a word in a program. For example the line...

PRINT "NEXT LEVEL:",LEVEL+1

...are 6 tokens:
- keyword PRINT
- string "NEXT LEVEL"
- comma
- the variable LEVEL
- the + sign
- the number 1

The app should show the numbers of tokens of a program, but this is still missing, sorry.


AnthonyJean 2020-05-13 20:57

Derp! Sometimes my brain doesn’t see the nose in front of my face! Thanks for the gentle reminder to code properly. I didn’t even stop to think of obvious things like dimensional arrays and data statements. Please slap me in the future.


Thanks for the help!


was8bit 2020-05-14 02:32

:)


AnthonyJean 2020-05-17 01:19

Gave it a rewrite. Looking for more suggestions to improve code. A lot smaller now.


was8bit 2020-05-17 04:50

... will give it a look over later, as i am over my head in work now :/


was8bit 2020-05-22 11:50

Ok, one thought...

Where you use ...

DO
KP$=INKEY$
GOSUB WHICHWAY
IF GOEAST$="Y" THEN GOTO ROOM14
IF GOWEST$="Y" THEN GOTO ROOM17
IF GOSOUTH$="Y" THEN GOTO ROOM16
IF KP$="I" OR KP$="H" THEN GOTO ROOM15
WAIT VBL
LOOP

Really should figure out a system for using arrays.. so lets say your map is size 9x9, then
RXMAX=9
RYMAX=9
DIM ITEMS(RXMAX,RYMAX,9)
DIM STATUS(RXMAX,RYMAX)

Would let you put up to 9 things in a room...

ITEM(1,4,1)=2

If item2 is a key, then you just put a key in there...
When player goes to,room 14 and picks up the key, then use
ITEM(1,4,1)=0
To remove the key

With carefull planning you should use 1 main DO LOOP, AND USE INDEXES TO HELP NAVIGATE..

RX=1
RY=4
References room 14 ... so maybe

NEWROOM:

Use arrays to build,text like
For I=1 to 9
If ITEMS(RX,RY,I)=2 then print "A key"
Next i

DO
KP$=INKEY$
GOSUB WHICHWAY
IF GOEAST$="Y" THEN
RX=RX+1
GOTO NEWROOM
END IF

LOOP

... This is really something you would want to start fresh, keeping this version as a reference, and just copy your image data ... would require careful planning and such but would WAY reduce tokens, and allow more flexibility and expansion :)


AnthonyJean 2020-05-30 02:09

Great advice! Thanks!


was8bit 2020-05-30 05:07 (Edited)

Glad to be helpful :)

Deciding how to organize your code can be the hardest part of programming, there is always more than one way to get the results you want...

Sometimes i will look at something i wrote awhile ago, and cannot immediately figure out what i was doing... and unless i really want it (like to remix it or borrow something from it) i just leave it alone... sometimes i come up with really creative code ;)


Log in to reply.