January 22, 2019, 06:05:24 PM

Author Topic: "Identifier ObjectEnumerator not found"  (Read 180 times)

Offline Cosmo

  • Jr. Member
  • **
  • Posts: 11
"Identifier ObjectEnumerator not found"
« on: December 09, 2018, 12:45:27 PM »
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

Offline Derron

  • Hero Member
  • *****
  • Posts: 1557
Re: "Identifier ObjectEnumerator not found"
« Reply #1 on: December 09, 2018, 01:03:48 PM »
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
  1. SuperStrict
  2. Framework Brl.StandardIO
  3.  
  4.  
  5. Global blocksArray:Int[] = [1,2,3]
  6. Global b:Int = 0
  7. CheckBlocks(b)
  8. Print b
  9.  
  10. Function CheckBlocks(block:Int)
  11.         For block = EachIn blocksArray
  12.                 If block = 2 Then Return 'or whatever you check there
  13.         Next
  14.         Return
  15. End Function
  16.  
-> it prints "0"

bye
Ron

Offline Cosmo

  • Jr. Member
  • **
  • Posts: 11
Re: "Identifier ObjectEnumerator not found"
« Reply #2 on: December 09, 2018, 01:09:14 PM »
Block is a type

Offline Derron

  • Hero Member
  • *****
  • Posts: 1557
Re: "Identifier ObjectEnumerator not found"
« Reply #3 on: December 09, 2018, 01:12:50 PM »
I already edited my post above.


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

Offline Cosmo

  • Jr. Member
  • **
  • Posts: 11
Re: "Identifier ObjectEnumerator not found"
« Reply #4 on: December 09, 2018, 01:19:18 PM »
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.

Offline Derron

  • Hero Member
  • *****
  • Posts: 1557
Re: "Identifier ObjectEnumerator not found"
« Reply #5 on: December 09, 2018, 07:52:02 PM »
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
  1. Type TBlock
  2.   Field x:int
  3.   Field y:int
  4. ...
  5. End Type
  6.  
  7. Global blocks:TList = new TList
  8.  
  9. for local i:int = 0 until 10
  10.   local b:TBlock = new TBlock
  11.   b.x = 10 * i
  12.   b.y = 10
  13.   blocks.AddLast(b)
  14. next
  15.  
  16. function BlockOccupiesArea:int(x:int, y:int)
  17.   for local b:TBlock = EachIn blocks
  18.      if b.x >= x and b.x + b.width <= x and b.y >= y and b.y + b.eight <= y then return True
  19.   next
  20.   return false
  21. end function
  22.  

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


bye
Ron

Offline Cosmo

  • Jr. Member
  • **
  • Posts: 11
Re: "Identifier ObjectEnumerator not found"
« Reply #6 on: December 10, 2018, 05:02:05 PM »
oh, thanks