Code center > Bugs and fixes

Shooting energy endlesly

<< < (2/3) > >>

Numsgil:
Ironically I haven't taken one

I think it's actually doing 2 7 store, which would be an empty info shot to sysvar #2.  Since there are no costs, nothing gets charged.

Incedentally, doing -2 .shoot store wwill produce an nrg shot with positive nrg even if you don't specify a .shootval.  I think it's something like 100 nrg.

EricL:

--- Quote from: Numsgil ---Incedentally, doing -2 .shoot store wwill produce an nrg shot with positive nrg even if you don't specify a .shootval.  I think it's something like 100 nrg.
--- End quote ---

The default nrg shot when .shootval is 0 is .nrg / 100, so you must be right and it can't be -2 7 store but I don't understand why the sub doesn't make it -2 and not 2.

Sprotiel:

--- Quote from: EricL ---The default nrg shot when .shootval is 0 is .nrg / 100, so you must be right and it can't be -2 7 store but I don't understand why the sub doesn't make it -2 and not 2.
--- End quote ---
Then we have it! VB does integer divisions in a very peculiar way: it performs the division as there were floats and rounds the result. Which means that 51 / 100 = 1 but 49/100 = 0. So either there's an integer division, or the result of the division is rounded. Whatever the case is, the energy of the shot becomes 0 when the bot's energy falls below some level (49.5 or 50, I suppose).

And '2 sub' really makes -2, because it's equivalent to '0 2 sub'.

Numsgil:
Are you sure it's 2 sub?

Does *-12 return 0 or nothing?  I thought it returned 0, but if it returns nothing then it would indeed be a negative 2 shot.

Sprotiel, that seems like a good explanation.

EricL:
Sprotiel is completely correct (almost) w.r.t. why there is no nrg loss.  I've stepped through the code to verify what is happening.  VB is indeed rounding the result to 0, but not becuase of integer division.  Internally, .nrg is maintained on the bot structure as a Single, not an Integer.  VB is correctly coercing the '100' to a Single when performing the division.  But the result is then assigned to a temporary varable which is declared as a Long.  This is where the rouding occurs.

I've fixed this for the next drop by using a Sinlge vauled temp varible.  Note that this one change addresses similar rounding bugs w.r.t. venom shots, waste shots and even nrg request shots....

Additionally, I think Sprotiel is correct that *-12 does nothing.


--- Code: --- Case 1 '*number
        If CurrentFlow <> CLEAR And .DNA(a).value <= 1000 And .DNA(a).value > 0 Then
          PushIntStack .mem(.DNA(a).value)
          If .DNA(a).value > EyeStart And .DNA(a).value < EyeEnd Then
            rob(n).View = True
          End If
        End If
--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version