Array or Tlist ??

BlitzMax Forums/BlitzMax Beginners Area/Array or Tlist ??

Hi folks. I've some experience of B3D, managed to suss how to populate 10 strings with variable user input - Howvever I'm only just getting to grips with BMax. Would it be best to use a Tlist or an array for indivdual character manipulation within BMax ?

In general the same rules for b3d apply in bmx.

A static array will always be faster than a Tlist.
Also you can easier access elements of a static array than those of a type list.

If you have a limited number of elements (10 in your case) I would mostly prefer a static array. But it really doesn't matter with modern pc's.

If you have lets say 1.000 or more elements it does!

Cheers Grisu - static array it is then...

I think a dynamic array would be better. (no real difference)

this one resizes each time you press enter...

kind of a mess. code wise. got carried away.

SuperStrict
Global mystringarray:String[]
Global Number_of_Lines:Int
Global GAME_OVER:Int = False
Global Line_Number:Int

Graphics 640,480,0
mystringarray = mystringarray[..1]

Repeat
	
	mystringarray[Number_of_Lines] = gl_input$(10,10,">")
	Local up:String = mystringarray[Number_of_lines]
	up = up.ToUpper()
	
	Select up
		Case "EXIT"
			GAME_OVER = True
		Case "QUIT"
			GAME_OVER = True
		Case "SHIT"
			mystringarray[Number_of_lines] = "Watch Your Mouth!!!"
		Case "FUCK"
			mystringarray[Number_of_lines] = "Do You use that mouth to kiss your Mother?"
		Case "HELLO"
			mystringarray[Number_of_lines] = "Well Hi There!"

	End Select
	
	Number_of_Lines:+1
	mystringarray = mystringarray[..Number_of_Lines+1]
	
	'If mystringarray[Number_of_lines] = 

Flip
Until GAME_OVER
End 


'-------------------------------------
Function gl_input:String(x:Int , y:Int , prompt:String = "?")
	Local m:String
	Local key:Int
	Local Length:Int
	
	Repeat
		Cls
		SetScale 1 , 1
		SetColor 0,150,0
		DrawText prompt$+m$,x,y
		draw_Output()
				
		key = GetChar() 
		
		If key>0
				If key = KEY_ENTER
					Return m$
				EndIf
				If key = KEY_BACKSPACE
					Length = Len(m$)
					m = m[..Length-2]
				EndIf
			m$ = m$ + Chr(key)
		EndIf
		
	
 	Flip
	Until KeyHit(KEY_ESCAPE)

End Function

Function draw_Output()
	SetColor 255,255,0 ; SetScale(2,2) 

	For Local Lines:Int = 0 To Len(mystringarray) - 1
		DrawText mystringarray[Lines],10,100+(TextHeight("X")*(Lines*1.25))
	Next
	
End Function




I tried to post this last night with an explanation but the site was down:

Strict
Local me$ = "hello"

Print Chr(me[4]) 'prints o (string is a zero-based array)

Local array$[3]

array[2] = "Jake"

Print Chr(array[2][0]) 'prints J
Print Chr(array[2][1]) 'prints A

Local List:TList = New TList
List.AddLast("one")
Print Chr(String(List.Last())[1]) 'prints n


Cheers guys,this was proving a stumbling block...

@ bradford6 your Case statements LOL :-}

@ Grey - I'll creep my revised project those baby steps forward again. Cheers - My motivation for re-doing a whole project that was so near to just needing bells and whistles (but was potentially fundamentally flawed in B3D) in a new programming language requires more dedication than I'd anticipated.... Rome wasn't built in a day.....

Just ran both your pieces of code -- very helpful with rapidly progressing individual character access within a string / array.

A static array will always be faster than a Tlist.
That depends on what operations you're using them for.

My static array is being populated with user input strings which will stay static without any further modification once populated. Is Tlist a better option ... ?

requires more dedication than I'd anticipated
Yeah, the whole reason I made a game framrwork is I was commisioned to do a match-3 game using my BlitzPlus engine but early on in discussions the producer wanted some fancy 3D card style effects and I knew I'd have to port to Max. I thought it might take a little while, but when I got really into it and found all this mini problems and things that needed fixing (in BMax (they are fixed now mostly)) and lots of oddities about the language the project suddenly was going to take MUCH longer. But I was determined to make something reuseable, hense the framework, so my next game (after the match-3) will be much quicker :-)

My static array is being populated with user input strings which will stay static without any further modification once populated. Is Tlist a better option ... ?
Probably not. A TMap might be though.

Hmmm... not had the joy of TMap as yet... all in good time.