Ranking
You can also use maths to get a particular digit:

lua code:
function getDigit(num, position)
return math.floor((num / (10 ^ (position-1))) % 10)
end

echo("Third digit: " .. getDigit(423, 3))
-- Third Digit: 4
:D
Is there a list of tables somewhere? By tables I mean things such as get_player_info(1).injury or get_body_info(player, bodypart).rot. If this list included all of them that would be convenient
Last edited by fett175; Jul 22, 2012 at 07:06 AM.
I don't think so. The best I can offer is every table in _G (every global table).
Signature temporarily out of order.
Sure you can:

lua code:

function write_result(stream, desc, func)
a = func()
stream:write(string.format("%s: \n", desc))
for k,v in pairs(a) do
stream:write(string.format("\t%s = %s\n", k, v))
end
end

f = io.open("tables.txt", "w")

write_result(f, "Player Info Table", function() return get_player_info(0) end)
write_result(f, "World State Table", function() return get_world_state() end)

f:close()

echo("Done")


This script outputs the keys and current values into "tables.txt". It's simple to add new functions, just add in another write_result under the others, for example:

lua code:

write_result(f, "Body Info Table", function() return get_body_info(0, 0) end)


Here's what running it output for me in a new game:

Player Info Table: 
    num_textures = 13
    injury = 0
    name = Blam
    score = 0
World State Table: 
    winner = -1
    selected_body = -1
    replay_mode = 0
    selected_joint = -1
    turn_timeout = 38447
    selected_player = 0
    num_bouts = 0
    game_paused = 0
    turn_timelimit = 15
    game_type = 0
    frame_tick = 70355
    game_frame = 500
    reaction_time = 15
    num_players = 2
    turn_frame = 0
    match_frame = 0
If you just want a quick refference, running the SDK file for a function that returns a table should echo all of the keys and their current values.

/ls sdk/get_game_rules.lua
Last edited by Blam; Jul 22, 2012 at 02:52 PM.
:D
Hmmm... That might be some of what I was looking for Blam.
But I just started learning lua and I'm a nooblet so I got some questions for you:
1) Where are you getting those terms in that first lua code, or is that just something i have to learn to remember? (such as the "Player Info table" and "World State table"). What I think I need is a reference to the tori-specific tables like this (i think they're tori-specific lol)
2) I think \n is a new line? What are \t%s if you don't mind explaining.
3) For the script that returns that table--are all of the results a function...thingy? Like I could type Get_World_Info.num_players and it would pull out the number 2?

P.S. thanks psy and blam for trying to answer my first question
Ok,
1) The strings are just for decoration in the file. They don't mean anything.
2)
\n        New line
\t        Tab (Big space, for indenting)
%s        Where the parameter will go.
Example:

lua code:
k = "Hello"
v = "World"
output = string.format("\t%s = '%s'\n", k, v)

echo(output)
-- Hello = 'world'
--


3) The results are a key pair table. This means each value has a specific key:

key            | value
---------------+---------
winner         | -1
selected_body  | -1
replay_mode    | 0
selected_joint | 0
name           | Blam
To iterate over a key pair table, you use the pairs function like this:

lua code:
world_state = get_world_state()
for key, value in pairs(world_state) do
echo(key .. " = " .. value)
end
:D
ah, thats helpful, thanks
One more for now. How would I make a player say something? Like in your tutorials only echo() was used, but I dont know any other of the commands
I don't think that you can send chatmessages with Lua. The only thing that comes to my mind is /run_cmd("em your_text") which will run the /em command and print text over tori's / uke's head.
Signature temporarily out of order.
Another question: Is it possible to change the strength of particular joints in the middle of a game? (sorry if this is obvious, I just want to know what is possible before spending hours to learn to script this game and then learning that my idea is not possible)