Bug. (?) Command First doesn't return First type.

Blitz3D Forums/Blitz3D Programming/Bug. (?) Command First doesn't return First type.

Braincell(Posted 2005) [#1]
Here's the code. This shouldn't be happening. The output is "1,1,2,2,3,3" , but in my opinion the function should point to the first one so it should be "1,1,1,1,1,1". If i'm the first to find this bug, do i get a prize?

Type test
	Field omg
End Type

t.test = New test
t\omg = 1
t.test= New test
t\omg = 2
t.test = New test
t\omg = 3
t.test = New test
t\omg = 4
t.test = New test
t\omg = 5

t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)

WaitKey

Function PrintOMG(t.test)

n=1
For t.test = Each test
	If n=1 Then Print "First omg = " + Str(t\omg)
	n=n+1
Next

End Function



In case you're wondering "OMG" stands for "Oh My Gawd!".


It can be fixed in this way:
 
t.test = First test
t = before t
PrintOMG(t.test)

which imo further points out this is a real bug?


tonyg(Posted 2005) [#2]
Very odd...
Type test
	Field omg
End Type
For x = 1 To 3
t.test = New test
  t\omg = x
Next
For x = 1 To 3
  Print "***start***"
  t.test = First test
  Print Str(t)
  PrintOMG(t)
Next
WaitKey()
End
Function PrintOMG(z.test)
    For z.test = Each test
	   Print "First omg = " + z\omg + " N : " + n
    Next
	Print "*** Finish***"
End Function

Notice the handle of the t.test changes.
Other than curiosity for the bug, why are you doing it that way.
Why not...
Type test
	Field omg
End Type
For x = 1 To 5
t.test = New test
  t\omg = x
Next

For x = 1 To 5
  t.test = First test
  printomg(t.test)
Next

Function printomg(t.test)
  Print t\omg
End Function



Braincell(Posted 2005) [#3]
Other than curiosity for the bug, why are you doing it that way.
Why not...


This was bad coding, and a good example. I dont code it like that in my app. The key things i have to do in my app is pass the first type to a function and inside the function use a For Each to iterate through each type. It seems that using a For Each shifts the first type returned.

You'd have to think im a really bad coder to suggest something like that :) lol , but thats ok.

The example itself has the unneccesary code left from previous experiments. Your second bit of code doesnt reproduce the results either.


Ross C(Posted 2005) [#4]
Are you sure that's the correct way to pass a type to a function?

i vaguely remember something along the lines of...

Function print.test(blah)


hmmmm


Ross C(Posted 2005) [#5]
Ok, try changing the function to something like...

Function PrintOMG(e.test)


Problem solved :D Must be something to do with the type reference being passed incorrectly i say. I don't think that's the way you do it.


Ross C(Posted 2005) [#6]
This also works, so it must be something to do with your for next loop...


Type test
	Field omg
End Type

t.test = New test
t\omg = 1
t.test= New test
t\omg = 2
t.test = New test
t\omg = 3
t.test = New test
t\omg = 4
t.test = New test
t\omg = 5

t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)

WaitKey

Function PrintOMG(t.test)

	Print t\omg
	t = After t
	Print t\omg
	t = After t
	Print t\omg
	t = After t
	Print t\omg
	t = After t
	Print t\omg
	t = After t

End Function



Braincell(Posted 2005) [#7]
Chainging it to e.test still produces the error.

Specifically here is the code, is that what you meant?

Type test
	Field omg
End Type

t.test = New test
t\omg = 1
t.test= New test
t\omg = 2
t.test = New test
t\omg = 3
t.test = New test
t\omg = 4
t.test = New test
t\omg = 5

t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)
t.test = First test
PrintOMG(t.test)

WaitKey

Function PrintOMG(e.test)

n=1
For e.test = Each test
	If n=1 Then Print "First omg = " + Str(e\omg)
	n=n+1
Next

End Function




Oh and:
This also works, so it must be something to do with your for next loop...


Its not MY for next loops, its Blitz3Ds actually. And everyone will have the same problem i suppose. Probably just a small coding error while blitz was being made, its easy to fix.


Ross C(Posted 2005) [#8]
For the purpose of your code, you really don't need to pass across the type object anyways :o)