Tag Archives: jeux

End of the Nspire Lua Contest

Some time ago, we announced a contest : Nspire programming in Lua . This was a large scale contest since the total sum of the prizes was of about € 750, including three awesome TI-Nspire CAS CX !

The contest is now over !

With not less than 14 Lua programs submitted, we think this is a great success for a language so “new” on the TI-Nspire calculator!

We would like to thank all participants, regardless of their results!

The judges (Levak, Critor and myself) are going to analyze everything you have done in the coming days, and the results should be there soon !

In the meantime, here is the list (just name + Screenshot) of entries received.

We recall that these programs, unless otherwise stated on the download page are subject to the following license : CC BY-SA 2.0 . Not respecting the terms of this license will result in legal consequences. The authors of the respective programs can change their licence at their will by contacting us by e-mail, of course.

Games : 7


Bobby Carrot – – – – Loïc P.

Image
Labyrinthe – – – – David L.


Reversi (Othello) – – – – Deep Thought.

Image
MasterMind – – – – Nick V.


TI-Cran – – – – Julien R.


Nspired Phoenix Lua – – – – Florent D.


Tactical Wars CX – – – – Rehn C.

Mathematics: 4


TabVar 3 – – – – JayTe.


LuaCS – – – – Jonathan L.


LogoMagic – – – – Jim B.


ABA Logique – – – – Loulou54.

Physics/Chemistry: 3


Planétarium – – – – Bastien V.

Image
FormulaOne – – – – Naji A.

Image
Formules de Chimie – – – – Paul J.

 

Well, while waiting for the results to come, fell free to comment on these programs !

Once again, congratulations to all !

Save a high score (or anything) without cheating possibility !

In this tutorial we’re going to take a look at a pretty interesting feature of the TI-Nspire framework in Lua : save and restore any kind of data directly in Lua, that lets us playing around with a high score for a game or any other configuration data for a more complex program.

Example : You just released a wonderful game. You’d like to share it with your friends, that way they can challenge you thanks to your high-scores system. But how is that working?

The first way you could think of is to use the var API. Therefore, we save the high score in the document as a global variable (math variable).

Your high score system is done ! Hum … wait a second, one of your friend managed to score 10 000 000 points to your game ! What the heck ? He simply modified the global variable you’re using as an high score, since it’s freely accessible via a Calculator application. Here, it is not hard to cheat !

A second way is to protect the first one by using math.eval() which lets us launch any TI-Basic instruction, as the Lock one for example. Then, if we do like so :

math.eval("Unlock highscore")
var.store("highscore", highscore)
math.eval("Lock highscore")

our high score variable will be write protected. But, since Lock is a TI-Basic command, it can be launch outside the Lua program. Things aren’t going to be better.

What about looking for a specific Lua command ? Actually, there is var.monitor() that probes a specified variable and checks if this variable will be changed. If so, on.varChange() event is called. This lets us to control any variable changes.

Here is an example :

function on.create()
  if not var.recall("highscore") then
    highscore = 0
    var.store("highscore", highscore)
  end
  var.monitor("highscore")
end
 
function on.varChange(list)
  for k, v in pairs(list) do
    if k == "highscore" then
      if var.recall(k) ~= highscore then
        return 1 -- it is an external change, block modifications
      else
        return 0 -- it is an internal change, allow modifications
      end
    end
  end
  return 0 -- allow modifications of other monitored variables if any
end

This code will disallow any external modification of the highscore variable, with the following error message :

Cannot accept change : Invalid input

Obviously, if you have to do this for multiple variable, for example configuration data, don’t do this since it is a heavy and repetitive method …
It is at this moment that we take a look to the documentation. We can see two trivial events : on.save() & on.restore().
In fact, this event couple does exactly what we expected to do from the beginning !

Actually, when the widget get closed (when we close the document, or copy/cut the widget) the on.save() event is called. You have to define on.save() to make it return any kind of value (boolean, number, string, table etc …). The next time the widget will open (when we open the document, or paste the widget), the on.restore() event will be called, with the data returned by on.save() as the parameter !

Here we are, easy-going :

function on.save()
  return highscore
end
 
function on.restore(data)
  if type(data) == "number" then
    highscore = data
  end
end
 
function on.create()
  if not highscore then
    highscore = 0 -- first time we initialize highscore
  end
end