Toribash
Yes, they are called "hooks".
Works like this:
add_hook("<hook_name>", "[identifier]", <function to be executed>)
for keyboard intput there are the hooks, "key_down" and "key_up". The function you provide has to take one argument, the key that got pressed. Example:
local function echoKeyCode(key)
  echo(key)
end

add_hook("key_down", "echoTheDamnKeyCode", echoKeyCode) --notice the missing brackets after  echoKeyCode
This will simply echo the key code of the key pressed.
In addition to that there is the function get_shift_key_state() which propably returns true if shift is pressed.

For mouse input there are "mouse_button_up", "mouse_button_down" and "mouse_move".

Functions for "mouse_button_up" and "mouse_button_down" have to take 3 arguments:
local function onButtenUp(mouseButton, x, y) --mouseButton: 1=left, 2=wheel, 3=right
  [...]
end
add_hook([...])
Whereas mouse_move just takes x and y.

There are also "bout_mouse_down", "bout_mouse_up", "bout_mouse_over", "bout_mouse_outside", "spec_mouse_down", "spec_mouse_up", "spec_mouse_over" and
"spec_mouse_outside" but they are not really needed.
Signature temporarily out of order.
Originally Posted by psycore View Post
Yes, they are called "hooks".
Works like this:
add_hook("<hook_name>", "[identifier]", <function to be executed>)
for keyboard intput there are the hooks, "key_down" and "key_up". The function you provide has to take one argument, the key that got pressed. Example:
local function echoKeyCode(key)
  echo(key)
end

add_hook("key_down", "echoTheDamnKeyCode", echoKeyCode) --notice the missing brackets after  echoKeyCode
This will simply echo the key code of the key pressed.
In addition to that there is the function get_shift_key_state() which propably returns true if shift is pressed.

For mouse input there are "mouse_button_up", "mouse_button_down" and "mouse_move".

Functions for "mouse_button_up" and "mouse_button_down" have to take 3 arguments:
local function onButtenUp(mouseButton, x, y) --mouseButton: 1=left, 2=wheel, 3=right
  [...]
end
add_hook([...])
Whereas mouse_move just takes x and y.

There are also "bout_mouse_down", "bout_mouse_up", "bout_mouse_over", "bout_mouse_outside", "spec_mouse_down", "spec_mouse_up", "spec_mouse_over" and
"spec_mouse_outside" but they are not really needed.

Thank you again.
Lawedan Computers, Inc
Forums|Wiki
Originally Posted by legsol View Post
Add "ls <scriptname.lua>" to profile.tbs in your Toribash root directory (typically CGames\Toribash-version\) to autoload the script.
DeScript would load scripts for you, but I think there are a few compatibility issues and DeFransen is banned, so it's unlikely to be updated soon.

Can't find profile.tbs. Do I make one?
Yes. A warning: if your script echo()s anything before the game is ready it'll crash. Try not to echo() anything outside of a callback in a script that you're autoloading; it won't work.
))<>((
Hello! I have been looking around almost everywhere and not found any example or anything about how you store more than 1 value inside a document.

However I would strongly appreciate a example or if itīs even possible to do so

--Loading the stored variables into a program

local Reader = io.read(file, 'w+')
if Reader:read(1stvariable) then
Variableinside program = 1stvariable
end
if Reader:read(2ndvariable) then
Variableinside program = 2ndvariable
end
Reader:close()

2nd question is

can I use io.write() to only edit the 1stvariable/2ndvariable

in other words how can I edit the 1stvariable/2ndvariable without editing the other one?

Hope I did describe what I want! I'm so thankful if anyone could take their time to help me!
At first: Always put code into [code] [/code] tags.

to your first question:
there are different ways to load variables from text files.
The easiest one is this:

Make your file look like this:
someVariable = "foo"
someOtherVariable = "bar"
aNumber = 5
thisIsATable = { "I", "am", "a", "table."}
and your script:
dofile("textfile.txt")
obviously replace name by the name of your file

now you can use the variables just like any other variables:
echo(someVariable)     --  will echo "foo"
echo(someOtherVariable)      -- will echo "bar"
echo(type(aNumber))     -- will echo "number"
echo(type(thisIsATable))     --will echo "table"
echo(table.concat(thisIsATable, " ")    -- will echo "I am a table."
advantages:
- simple and short.
- Will work for simple scripts.
- You can assign any value.

disadvantage: in my oppinion not the best way to code.

If you need something more advanced just ask again.

To your second question:

I don't think so. I guess you have to write the whole file again if you want to change a value.
Last edited by psycore; Oct 29, 2011 at 01:15 PM.
Signature temporarily out of order.
Ok thank you very much!

So then I just make

Variable = echo(someVariable)
to store "foo" in to Variable?

and then the question comes how can edit the values inside the .txt doc this way so the bot can remember the new values upon execution?
Last edited by CalaxII; Oct 29, 2011 at 06:36 PM.