This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hawkins627's profile picture

command.exec and variables

Started by hawkins627, 28 March 2017 - 12:53 PM
hawkins627 #1
Posted 28 March 2017 - 02:53 PM
This is probably a beginner question, but I have gotten pretty far by myself in this…

My goal was to have a command computer program receive redstone input from the left, begin a countdown timer that would say the countdown to people in a certain radius, and then when it hits zero it sends a redstone signal out on the right.


I accomplished this goal with a little help from google searches, but hit a wall on this one:


I am using the command.exec to say the countdown in a loop that needs to say the variable, but I can't get it to say the variable. Here is the part of the script in question (I didn't put in the whole thing…):


local i = 10

while i > -1 do

sleep(1)

commands.exec( "say @a[r=10] …")

i = i - 1

end


However all I get is:






and so on…


also tried with (i), {i}, "i", <i>, and ""i"" all with similar results or error message.


What am I doing wrong, or what am I missing here?


-Hawkins
Lyqyd #2
Posted 28 March 2017 - 06:58 PM
You'd probably want to concatenate the value into the string:


commands.exec("say @a[r=10] " .. i .. " is the value of i")

Notice that the string is finished, then there's a concatenation operator (the two periods), then the variable.
hawkins627 #3
Posted 28 March 2017 - 08:17 PM
Thank you! I knew there was a solution somewhere: .. i ..

That makes me feel :o/>)