Problem Table field 0 was not initialized!

Find quick help here to get you started with Hollywood
Post Reply
User avatar
Lerio69
Posts: 12
Joined: Sat Sep 24, 2016 11:47 pm
Location: Italy

Problem Table field 0 was not initialized!

Post by Lerio69 » Mon Sep 26, 2016 9:17 pm

Hello, this is my first post and probably my question is very noob :lol:

I have this function that work fine.

Code: Select all

Function OpenAIWFile(file$)
/* Read waypoints from aiw file */

split$ = {}
score$ = {}
value$ = {}
wp_x = {}
wp_y = {}
wp_branchID = {}
wp_score = {}
wp_wpseA = {}
wp_wpseB = {}
wp_bitfields = {}
j=0

OpenFile(1, file$)
While Not Eof(1) 
	row$ = ReadLine(1)
	split$ = SplitStr(row$,"=")
	Switch split$[0]
	Case "wp_pos":
		string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
		value$ = SplitStr(string$,",")
		wp_x[j] = Val(value$[0])
		wp_y[j] = -1 * Val(value$[2])		
	
	Case "wp_branchID":
		string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
		wp_branchID[j] = Val(string$)		
	
	Case "wp_bitfields":
		string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
		wp_bitfields[j] = Val(string$)		

	Case "wp_wpse":
		string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
		value$ = SplitStr(string$,",")
		wp_wpseA[j] = Val(value$[0])
		wp_wpseB[j] = Val(value$[1])		
	
	Case "wp_score":
		string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
		score$ = SplitStr(string$,",")
		wp_score[j] = Val(score$[0])		
	
	Case "WP_PTRS":
		j = j + 1		
	EndSwitch
Wend
CloseFile(1)
EndFunction
In this function I use only simple arrays. Now I want to replace the two arrays "wp_wpseA" and "wp_wpseA" with a single bidimensional array "wp_wpse".
But when I change the code to do this, I get the error: Table field 0 was not initialized!

This is the new function:

Code: Select all

Function OpenAIWFile(file$)
/* Read waypoints from aiw file */

split$ = {}
score$ = {}
value$ = {}
wp_x = {}
wp_y = {}
wp_branchID = {}
wp_score = {}
wp_wpse = {}
wp_bitfields = {}
j=0

OpenFile(1, file$)
While Not Eof(1) 
	row$ = ReadLine(1)
	split$ = SplitStr(row$,"=")
	Switch split$[0]
	Case "wp_pos":
		string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
		value$ = SplitStr(string$,",")
		wp_x[j] = Val(value$[0])
		wp_y[j] = -1 * Val(value$[2])		
	
	Case "wp_branchID":
		string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
		wp_branchID[j] = Val(string$)		
	
	Case "wp_bitfields":
		string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
		wp_bitfields[j] = Val(string$)		

	Case "wp_wpse":
		string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
		value$ = SplitStr(string$,",")
		wp_wpse[j][0] = Val(value$[0])
		wp_wpse[j][1] = Val(value$[1])		
	
	Case "wp_score":
		string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
		score$ = SplitStr(string$,",")
		wp_score[j] = Val(score$[0])		
	
	Case "WP_PTRS":
		j = j + 1		
	EndSwitch
Wend
CloseFile(1)
EndFunction
Whats wrong? :?
Thanks in advance

Tipsi
Posts: 8
Joined: Sun Feb 14, 2010 7:06 pm

Re: Problem Table field 0 was not initialized!

Post by Tipsi » Mon Sep 26, 2016 10:05 pm

With

wp_wpse = {}

have you only one Dimension. But you have two. With

wp_wpse[j] = {}

you create a new row.

Code: Select all

   Case "wp_wpse":
      string$ = TrimStr(TrimStr(split$[1],"(", False),")",True)
      value$ = SplitStr(string$,",")
      wp_wpse[j] = {}
      wp_wpse[j][0] = Val(value$[0])
      wp_wpse[j][1] = Val(value$[1])
Griessli
Tipsi

User avatar
Lerio69
Posts: 12
Joined: Sat Sep 24, 2016 11:47 pm
Location: Italy

Re: Problem Table field 0 was not initialized!

Post by Lerio69 » Mon Sep 26, 2016 10:19 pm

Thanks, this work! ;)

Post Reply