Good vs. Evil

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

duckfan77

Popular Member
Mar 18, 2013
80
683
118
47 Yep! Needs to get figured out soon, so drivers can practice for the State championship on Saturday.
 

duckfan77

Popular Member
Mar 18, 2013
80
683
118
46 They got it fixed. A bad encoder cable was causing the Talon (a motor controller) to freak out.
 

duckfan77

Popular Member
Mar 18, 2013
80
683
118
46 Yeah. In this case the controller was just refusing to pass negative voltage when told to, only allowing positive through.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
47 so... I had to chase down a fun little bug, happening inside the scripting part of rp_tracker. This means no debug tools and you don't even have access to a normal print function to print debug information (you technically have access to the print function, you just can't see the output).

There luckily is a way to print something, however it tries to mimic lua's print function as close as possible meaning it has all the bad parts of it and contains bugs some of which can't be solved at least,not in a sane way. It also adds extra information that is actually not meant to be read by humans thus there is even more stuff to sift through.

The result was caused when I tried to implement a function that would end a characters turn. This needed 3 new functions in the api. One to get the character whose turn it currently is, one to get the next character in the list and one to set it to a given character.

This means that the code to actually switch boils down to 3 lines of code
Code:
battle:setTurnTo(
  battle:getNextCharacter(
  battle:getCurrentCharacter()
  )
)
Now, for some reason, getNextCharacter would crash, stating that I was trying to index a nil value, meaning that getCurrentCharacter() did not return a character. Lets take a look at that code, shall we?
Code:
function fun:getCurrentCharacter()
  for k,char in pairs(battleData.characters) do
  if char.isTurn == 1 then
  return char
  end
  end
  end
now, using 1's and 0's for booleans isn't exactly the best, but mysql can't store real booleans so storing integers with a size of 1 is the best I can do. The bug is in this piece of code, can you spot it?

PHP turns every value it gets from the database into a string, this is not a problem for php as it is a very weakly typed language resulting in stuff like
PHP:
"php"== 0 //this is true
Lua on the other hand is not that weakly typed and although it happily converts strings and numbers when working on them, it does NOT do that when comparing.
This means that the if statement will never become true and thus a character will never be returned. All in all the bug was caused by 3 languages working slightly diffrent from each other:
MYSQL, as it can't store real booleans.
PHP for converting everything it gets from the database into strings and also by making it no problem thus very easy to forget that that is happening
Lua for converting strings and ints only when working on them and not doing so when doing comparisons.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,801
248
47 well, its a big project.
According to a firefox plug-in the server currently has 78024 lines of code, though that is with the whole codeigniter framework and files to setup the database. Both of those things are probably inflating the amount of lines by quite a lot.
For completeness sake
the client has 4398 lines of code
Websocket server : 965
Tests : 1396