Darwinbots Forum
Code center => Darwinbots Program Source Code => Topic started by: Botsareus on June 16, 2005, 12:02:51 PM
-
I am getting an erray is fixed or temporarly locked error over here:
EDIT: BAU June 16, 05 : THE CODE BELOW IS THE WRONG CODE , READ THE OTHER POST TO GET THE CORRECT CODE:
' creates a shot shooted by robot n, with couple location/value
Public Sub newshot(n As Integer, shottype As Integer, val As Long, rngmultiplier As Single)
Dim a As Integer
Dim vs As Integer
Dim ran As Single
Dim ShAngle As Single
If IsArrayBounded(Shots) = False Then
ReDim Shots(100)
maxshotarray = 100
End If
a = FirstSlot
If a > maxshotarray Then
maxshotarray = maxshotarray + 1
ReDim Preserve Shots(maxshotarray) '<------ Here
End If
Shots(a).Parent = n
Shots(a).FromSpecie = rob(n).fname 'Which species fired the shot
...
Now how the ##$#%%^hell is that happening? I did not mess with any of this code.
Here is what I think of vb right now: :plzdie: , but vb is not alive its a program , o well.
Ofcorse the temporary backwords compatible solution for me now is to "On Error GoTo kill" "kill: killrobot n"
-
Hmm, I've never gotten that error. Have you tried googling it?
And I'm not sure killing robots is "backwards compatible". How would you like it if you try to eat, the universe has a page fault and now you're dead.
-
Its a real error Num. And by backwords compatible I mean: "still works in the broken virsion" and dont worry about the little guys , there files is mutated before the simulation starts, There is no need for survival of the species. although I want it to work otherwise , for now my robots dont even reproduce properly. But I did it this way bc I favored speed over accurasy, just more fun that way. I gess it payed off bc I am getting some really funny errors like:
This array is fixed or temporarily locked (Error 10)
Not allarrays can be redimensioned. Even arrays specifically declared to be dynamic and arrays within Variantvariables are sometimes locked temporarily. This error has the following causes and solutions:
You tried to use ReDim to change the number of elements of a fixed-size array . For example, in the following code, the fixed array FixedArr is received by SomeArr in the NextOne procedure, and then an attempt is made to resize SomeArr:
Sub FirstOne
Dim FixedArr(25) As Integer ' Create a fixed-size array and
NextOne FixedArr() ' pass it to another procedure.
End Sub
Sub NextOne(SomeArr() As Integer)
ReDim SomeArr(35) ' Error 10 occurs here.
. . .
End Sub
Make the original array dynamic rather than fixed by declaring it with ReDim (if the array is declared within a procedure), or by declaring it without specifying the number of elements (if the array is declared atmodule level).
You tried to redimension a module-level dynamic array, in which one element has been passed as anargument to a procedure. For example, in the following code, ModArray is a dynamic, module-level array whose forty-fifth element is being passedby reference to the Test procedure:
Dim ModArray () As Integer ' Create a module-level dynamic array.
. . .
Sub AliasError()
ReDim ModArray (1 To 73) As Integer
Test ModArray (45) ' Pass an element of the module-level
' array to the Test procedure.
End Sub
Sub Test(SomeInt As Integer)
ReDim ModArray (1 To 40) As Integer ' Error occurs here.
End Sub
There is no need to pass an element of the module-level array in this case, since it's visible within all procedures in the module. However, if an element is passed, the array is locked to prevent a deallocation of memory for the referenceparameter within the procedure, causing unpredictable behavior when the procedure returns.
You attempted to assign a value to a Variant variable containing an array, but the Variant is currently locked. For example, if your code uses a For Each...Next loop to iterate over a variant containing an array, the array is locked on entry into the loop, and then released at the termination of the loop:
SomeArray = Array(9,8,7,6,5,4,3,2,1)
For Each X In SomeArray
SomeArray = 301 ' Causes error since array is locked.
Next X
Use a For...Next rather than a For Each...Next loop to iterate. When an array is the object of a For Each...Next loop, you can read the array, but not write to it.
For additional information, select the item in question and press F1.
-
Did you perhaps set the shots array as a fixed array? That's the only thing I can think of.
You must have changed something in the code, because I've never seen that error, and I've been messing around with the code quite a bit.
-
Now how the ##$#%%^hell is that happening? I did not mess with any of this code.
Look if you ever get it you will get it , otherwise for now you can care less. The quote above is from my first post ;I say clearly that I did not mess with the shots code.
-
Then I have no idea. Maybe it's a Mandelbug. A nasty bug type that is characteristically inexplicable and apparently random.
-
I am beginning to think my cpu over heated or something. It is summer out there.
But I put on error go to kill in there just as a safty mesure, I still think it was caused by the DNA robot with way too mutch Junk dna.
-
I FOUND THE PROBLEM.
IN MY FIRST POST I DID NOT POST THE CORRECT CODE BC THE TWO CODES ARE REALLY SIMILAR; The right code is called "createshot" (NOT "newshot").
And the cause of the error is right here:
createshot Shots(t).x, Shots(t).Y, -.vx, -.vy, -5, h, .nrg / 2, Shots(t).range, vbYellow
etc.
you cant pass shots(anything).anything to a sub or function that redims the shots inside!
O yea , mutated virsions of this: robot cause the error (don't know how usefull it will be)
-
Alright I fixed it in my code.
-
woohooo! :D
-
There is more then one like that , did you get all of them?
-
I changed the createshot function to use byval, which fixes all the calls to it
-
Brilliant
In the mean while I am evolving robots as we speack, nothing to watch on tv so I set it to high priority and "chillin'" on this forum.
-
Num , this does not fix all of the problem , the following also causes it:
"' calculates next shots position
Public Sub updateshots()"
uses "With Shots(t)" in the code
when a -5 shot gets checked it calls on "takepoison"
here is what happens in takepoison if the robot is dead: "KillRobot n"
after that it goes to "makepoff" , thats were another problem is, because we are still working "with .shots(t)" it is still keeping the array locked, that basterd. :D
If I find more I'll let you know
-
No, that should be okay, since it's not rediming the shots array inside the function.
If I understand it right, that is. If you actually catch another such problem, we can fix it.
-
Num, when it goes to makepuff it calls on createshot and then it does redim the shots array...
If you have With array anywere and even through a stack of nested calls you try to redim that array , that "with" statement will keep it locked.
I just tryed it without the "with" in the "updateshots" , it worked fine.
-
If you have With array anywere and even through a stack of nested calls you try to redim that array , that "with" statement will keep it locked.
I just tryed it without the "with" in the "updateshots" , it worked fine.
Are you sure, or are you assuming? Did it actually trip an error? Since we're not passing an array element to makepoff, I don't think it will cause any problems.
-
LOL < NO SHIT IT ACTUALY TRIPED THE ERROR I NEVER "ASSUME" STUFF LIKE THIS.
and without that "with" statement the error was gone!
-
Private Sub takepoison(n As Integer, t As Integer)
If Shots(t).FromSpecie = rob(n).fname Then 'Robot is imune to poison from his own species
rob(n).poison = rob(n).poison + Shots(t).value 'Robot absorbs poison fired by conspecs
If rob(n).poison > 32000 Then rob(n).poison = 32000
rob(n).mem(827) = rob(n).poison
Else
Dim power As Long
power = Shots(t).nrg / Shots(t).range * Shots(t).value
rob(n).Poisoned = True
rob(n).Poisoncount = rob(n).Poisoncount + power
If rob(n).Poisoncount > 32000 Then rob(n).Poisoncount = 32000
If Shots(t).Memloc > 0 Then
rob(n).Ploc = Shots(t).Memloc
Else
rob(n).Ploc = Int(Rnd * 1000) + 1
End If
End If
Shots(t).Exist = False
End Sub
I don't see a killrobot. DId you add that to your source?