Posted: 28th Nov 2021 5:39
Hi,

I'm trying to create a simple board using a bunch of small squares and got the error message:


Here is the code the error is complaining about:
+ Code Snippet
function createBoard(width, height)
	for w = 0 to width
		for h = 0 to height
		CreateObjectBox(1, 1, 1)
		SetObjectPosition(1, 1*w, 1*h, 0)
		next h
	next w


EDIT:
Round 2
+ Code Snippet
function createBoard(width, height)
	for w = 0 to width
		for h = 0 to height
		CreateObjectBox(1+(w*h), 1, 1)
		SetObjectPosition(1+(w*h), 1*w, 1*h, 0)
		next h
	next w
endfunction

No luck!
Posted: 28th Nov 2021 6:01
When width = 6 and height =8 you will get exactly the same number as width = 8 and height = 6
I think you might want to use a sequential number as the object id
also createobjectbox() should be CreateObjectBox(1+(w*h), 1, 1, 1) // Requires three 1s because width, height, depth
Posted: 28th Nov 2021 6:44
lso createobjectbox() should be CreateObjectBox(1+(w*h), 1, 1, 1) // Requires three 1s because width, height, depth

Ok, thanks for the advice. I just started with AppGameKit and am hoping to win the e-books. It?s 1am here so I will try to fix it early in the morning. Is there a way to automatically allocate the id?
Posted: 28th Nov 2021 7:21
Ok, thanks for the advice. I just started with AppGameKit

Ask as many questions as you like! We are all happy to help.
Looking forward to your TD entry.
Posted: 28th Nov 2021 8:25
Is there a way to automatically allocate the id?
yes. see HERE.

so, you'd do something like:
+ Code Snippet
SetErrorMode(2)

// set window properties
SetWindowTitle( "boxes" )
SetWindowSize( 1280,720, 0 )

// set display properties
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 ) 
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 ) 

GLOBAL Map as Integer [4,4]
for x = 0 to 4
	for z = 0 to 4
		ThisBox = CreateObjectBox(1,Random(1,3),1)
		SetObjectPosition(ThisBox, x, 0, z)
		SetObjectColor(ThisBox,Random(128,255), Random(128,255), Random(128,255), 255)
		Map[x,z] = ThisBox
	next z
next x
	
do

    If GetRawKeyState(27) then Exit    

	if Last# + 0.1 < Timer()
		SetObjectColor(Map[Random(0,4),Random(0,4)],Random(128,255), Random(128,255), Random(128,255), 255)
		Last# = Timer()
	Endif
	
    Print( ScreenFPS() )
    Sync()
loop

the idea is to let AppGameKit allocate the object IDs (my preference) but you'll need some way to reference those object IDs later.

so, if the boxes represent your map, make an array (ie, Map[4,4] ) for easy reference to those IDs.

if you want to change one of the boxes, say the box at 1,1 then the ID of that box would = Map[1,1]

this:
+ Code Snippet
	if Last# + 0.1 < Timer()
		SetObjectColor(Map[Random(0,4),Random(0,4)],Random(128,255), Random(128,255), Random(128,255), 255)
		Last# = Timer()
	Endif

...finds the object id at a random location in the Map and changes its color, for example.

otherwise, do yourself a big favor and skim through the guides and the rest of the help files
Posted: 28th Nov 2021 22:41
+ Code Snippet
Global BOARD_SIZE as Integer

BOARD_SIZE = (BOARD_SIZE_WIDTH * BOARD_SIZE_HEIGHT)

Global boardpiece as BoardPiece[BOARD_SIZE]


error: Unexpected token "board_size", Array dimension must be an integer literal or a constant
Posted: 28th Nov 2021 23:10
When defining an array you can only use a literal or constant.
You can however do this;

+ Code Snippet
Global boardpiece as BoardPiece[]
boardpiece.length = BOARD_SIZE


Also I would recommend against making your type the same name as your variable. It tends to break the goto definition function within the IDE