"Identifier ObjectEnumerator not found"

Started by Cosmo, December 09, 2018, 12:45:27

Previous topic - Next topic

Cosmo

For some unknown reason when I attempt to put an For = EachIn loop inside a function it has the error "Identifier ObjectEnumerator not found"

Function cb_check_blocksanity(_blocksanitycheck)
' what
   For _blocksanitycheck=EachIn Block
      If _temp2 - _block.x > 0 And _temp2 - _block.x < _block.sx Return ' Do not insert if intersect
      If _temp3 - _block.y > 0 And _temp3 - _block.y < _block.sy Return ' Do not insert if intersect
   Next

Return


_blocksanitycheck is defined as an Int. It's called from another file. The error is still there if the code is in the same file, without the func call, but it disappears if it is not within a function.
End Function

Derron

#1
Use "superstrict" on top of your file - I bet you will spot errors already.
What is "Block" - a list?

To "eachin" over something the "something" needs to implement ObjectEnumerators - as TList (linkedlist) and TMap do.


Edit: What is your function intended to do? It is planned to return "Block count" if the conditions were not met, or something lower if they do - is that right? Why not return the value itself -> "return block"?
You pass a simple type - which is an "int" in this case - and you pass it as "copy" not "reference". Means if you modify "_blocksanitycheck" within the function, you will not change/alter it outside of the function. For this you need to use "_blocksanitycheck:int var".


Code (BlitzMax) Select

SuperStrict
Framework Brl.StandardIO


Global blocksArray:Int[] = [1,2,3]
Global b:Int = 0
CheckBlocks(b)
Print b

Function CheckBlocks(block:Int)
For block = EachIn blocksArray
If block = 2 Then Return 'or whatever you check there
Next
Return
End Function

-> it prints "0"

bye
Ron

Cosmo


Derron

#3
I already edited my post above.


Quote from: Cosmo on December 09, 2018, 13:09:14
Block is a type
You can only "eachin" over types implementing the Enumerator-stuff.


I go d'accord with you that the error message is a bit "less helpful" for beginners.

bye
Ron

Cosmo

#4
yeah it's an extremely confusing error message. i only started properly using bmx a week ago, was using bplus before but it was annoying me so i switched

thanks


EDIT: The function basically just inserts a block, calling a method of the Block type to do it, and then rendering a rectangle based on the parameters passed to the method. This EachIn is checking if there is already a block in the x and y coordinate range of the block insertion area. since the project is in its very early stages (i plan to have it so you can upload levels to a site and stuff, and there will be contests), the args are hardcoded - 0,0,128,128,128,32,32 = Block at 0,0 with colour RGB 128,128,128 and a size of 32x32 pixels.

Derron

so you basically have:

- a list, array, map .... containing all entries
- a function which returns "true" or "false" if an entry occupies the x,y,width,height already

?

Code (BlitzMax) Select

Type TBlock
  Field x:int
  Field y:int
...
End Type

Global blocks:TList = new TList

for local i:int = 0 until 10
  local b:TBlock = new TBlock
  b.x = 10 * i
  b.y = 10
  blocks.AddLast(b)
next

function BlockOccupiesArea:int(x:int, y:int)
  for local b:TBlock = EachIn blocks
     if b.x >= x and b.x + b.width <= x and b.y >= y and b.y + b.eight <= y then return True
  next
  return false
end function


Something (untested) like above might do what you try to achieve.


bye
Ron