plunking data

Blitz3D Forums/Blitz3D Programming/plunking data

OK I can make a databank of 10 by 10 and I can read the databank... how to I write to the databank??? poke???

Look I got a gameboard 10,10.

restore gameboard

.gameboard
Data 0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,1,2,0,0,0,0
Data 0,0,0,0,2,1,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0
Data 0,0,0,0,0,0,0,0,0,0

I mean I can read it to set up the gameboard and the pieces (1=red 2=blue) but HOW can I update the array???

If I'm not mistaken, a 'databank', as you put it, is static information. Just a big listing of constants in a specified order, so to speak, if I'm right.

Thats exactly what I was asking... I wish there was some way to write data to a location in the databank... I mean you can read x,y,z but only poke A...

Maybe its a feature request?

OR maybe I just need to figure out how to take the static array and read it in to a dim...

I may have been thinking about htis backwards!
;]

rook

Where there's a will there's a way, so to speak ;)

Any anyway, it wouldn't be too hard if you know how many rows and columns a data statement has.

What you propose is achievable with only a little coding.

A databank is like a 1-dimensional array, just imagine:
DIM databank(1, n)

The n can be any number of bytes, but the 1 can only be 1. So if you want to read that out as if it were a 2 dimensional (or 3, or 4d) array, you just have to know how many elements to a row, how many rows etc. Then write a formula that converts that to the 1d array.

For example:
If you have an array(6,15)

The databank is 6x15 elements (let's assume each element is only one byte), so you create a bank with that many bytes.

When you want to read or write to x, y and you need to know which byte of the bank to affect:
byte = (y*6) + x

And if each element is more than one byte, just multiply by that amount.

You can go further and have arrays which have different amounts of elements on each row - you just have to store that information (maybe as the first element on each row).

Having said all this... is there a reason you want to use a bank instead of an array in this instance?

I am having trouble setting the pieces on the gameboard... othello type game...

byte = (y*6) + x


Ah, the good old "poke a character into the screen memory" formula for the vic20 and c64. Least that's probably the last time *I* ever used it. :)

Atari 800 for me... seriously though... manipulating arrays seems a bit pokey look atthis code here:
; Hexathello (OK Othello but I hope to get the square thing figured out
; then nail a hex thing!
; Ralph Dunn
Graphics3D 800,600,16,2
SetBuffer BackBuffer()

player=CreatePivot()
camera=CreateCamera(player)
light=CreateLight()
RotateEntity light,45,10,0
PositionEntity light,0,53,-69
AmbientLight 48,48,48    ; was 32,32,32

EntityType camera,1
PositionEntity camera,0,53,-69
RotateEntity camera,35,0,0

Global square
Dim board1(9,9)
Dim board.squareT(9,9)	; A 10x10 board

Global ent
Global xx
Global zz
Global colour
Global thing
Global what
Global snog
Global wp
Global bp
Global colorflag
Global SQempty

SQempty = 100
; ###################################### Fill board1 with 0
For r=0 To 9
	For c=0 To 9
		board1(r,c)=0
	Next
Next
; ########################### Then plunk in the start locations
board1(5,4)=1
board1(6,5)=1
board1(5,5)=2
board1(6,4)=2


; #######################################  Load Mesh Objects
gameboard=LoadMesh("squareboard.b3d")
UpdateNormals gameboard
EntityFX gameboard,0
ScaleEntity gameboard,5.5,5.5,5.5
EntityShininess gameboard,1

empty=LoadMesh("square.b3d")
EntityPickMode empty,2
EntityShininess empty,1
HideEntity empty

Global wpiece=LoadMesh("hexpiece.b3d")
UpdateNormals wpiece
EntityShininess wpiece,1
HideEntity wpiece

Global bpiece=CopyMesh(wpiece)
RotateEntity bpiece,180,0,0
UpdateNormals bpiece
EntityShininess bpiece,1
HideEntity bpiece

; ######################################  Plunk Tiles
; -----------------> Thanks Big10p for the type and plunk code
; -----------------> :] (MightyMac And Wolron too)
Type squareT
	Field entity
	Field x#, z#
	Field kolor
End Type

row_pos# = -45
For row = 0 To 9
	col_pos# = -45
	For col = 0 To 9
			n.squareT = New squareT
			n\entity = CopyEntity (empty)
			n\x = col_pos
			n\z = row_pos
			n\kolor = 0
			board(row,col) = n
			EntityPickMode n\entity,2
			PositionEntity n\entity,n\x,1,n\z
			col_pos = col_pos + 10
	Next
	row_pos = row_pos + 10
Next


; ############################################## Start of Game Loop
ShowPointer 

colorflag=1

SQempty = SQempty-4

While Not KeyDown(1)

If SQempty = 0 Then colorflag=3

x=MouseX()
y=MouseY()

e=CameraPick(camera,x,y)
	If e<>entity#
		If entity Then EntityColor entity,255,255,255 
		entity#=e
	EndIf
;If KeyHit(50)>=1 Then musicflag=1-musicflag
If MouseHit(1) = True Then
	hat=CameraPick(camera,x,y)
	If hat=0 Then Goto outme
		colorflag=1-colorflag
			For n.squareT = Each squareT
				Select entity 
					Case entity
					xx=EntityX(entity)
					zz=EntityZ(entity) 
					Default 
					pp=0
				End Select
			Next
.outme

	If colorflag = 0 Then update_board()
	
	If colorflag = 1 Then put_black()
EndIf

If entity#
	EntityColor entity,0,120,255 ; 73,253,146 lime 254,216,38 gold 254,80,232 magenta
EndIf

;If musicflag=1 Then ChannelVolume play_annoy,0.4 Else ChannelVolume play_annoy,0

UpdateWorld
RenderWorld

Text 0,10,"X: "+x
Text 0,20,"Y: "+y
Text 0,30,"Z: "+z
Text 0,50,"THING: "+e
Text 0,60,"XX "+xx
Text 0,70,"ZZ "+zz
Text 0,90,"SQUARES: "+SQempty

Flip

Wend

End


Function update_board()

For row = 0 To 9
	For col = 0 To 9
		g = board1(row,col)
		If g=1 Then 
			wp=CopyMesh(wpiece)
			PositionEntity wp,xx,2,zz
		EndIf
	Next
	
Next
SQempty = SQempty - 1

End Function

Function put_black()
;gonna start black AI here
;soon

; first check the corners

; then check the sides

; then pick 10 random places

; pick one of those 10
	
	SQempty = SQempty-1
End Function



while I can get it to wite the piece on the screen I cannot get it to read the array to put the initial pieces OR update the array... All I get is

ILLEGAL TYPE CONVERSION

I don't think this is a feature... I think this is something that may need to be addressed! Though I do realize I am possibly doing something wrong.

Possibly... maybe probably!

I wish I could see a lottle window where I could view th array in its whole!

Ah, the good old "poke a character into the screen memory" formula for the vic20 and c64. Least that's probably the last time *I* ever used it. :)

*You* can kiss my shiny metal ass. :)

I wish I could see a lottle window where I could view th array in its whole!
If that's what you want then WRITE IT.

Rook, I regrettably haven't had much time to help you out lately but BRIEFLY overlooking what you are doing, it appears to me that you are making this way more complicated than what it is.

Othello is a 2D game, so why don't you start by writing a 2D game. Skip the 3D for the time being so that you don't have to worry about that for now. Get the GAME working first, then add 3D later. Trust me, it will be a lot easier to convert it to 3D later than it is from scratch.

You are trying to tackle more things at once than are necessary. Take it in steps.

And I HIGHLY doubt that you need to use banks for your Othello game. Arrays should be all that you need (and should make it simpler). I have yet to even use a bank myself.

little bug or uselessness:
Select entity 
					Case entity
					xx=EntityX(entity)
					zz=EntityZ(entity) 
					Default 
					pp=0
				End Select

where is the use of select entity case entity as it might never be something else than entity?


the illegal type conversion might come from the fact that you define the type after you have first declared a variable ( array ) of it's type.

btw:
you should avoid spaghetticoding (using goto)... now it is the best time to learn it :)
a simple if hat <> 0 would have done it