Bot = getBot()
Inventory = Bot:getInventory()
Botx = Bot.x
Boty = Bot.y

Bot:setBubble(Bubble.talk)
sleep(1500)
Bot:say("Hello fellow Human!")
Bot:setBubble(Bubble.none)

Bot.auto_collect = true

Broken = false
Movement = "UP"
while Broken == false do

    for i,Item in pairs(Inventory:getItems()) do
        if Item.id == 2 or Item.id == 3 or Item.id == 5032 or Item.id == 5033 then
            Bot:setBubble(Bubble.talk)
            Bot:say("Ew, yucky dirt! I'm moving.")
            sleep(1250)
            Bot:setBubble(Bubble.brb)
            Bot.auto_collect = false
            sleep(1250)
            Bot:drop(Item.id,200)
            sleep(750)
            Bot:setBubble(Bubble.none)
            if Movement == "UP" then
            Bot:moveUp(2)
            Movement = "Down"
            else
            Bot:moveDown(2)
               Movement = "UP"
            end
            sleep(1000)
            Bot.auto_collect = true
        elseif Item.id == 242 then
            Bot:setBubble(Bubble.talk)
            sleep(1500)
            NumberOfWLS = Inventory:findItem(Item.id)
            Bot:say("I just got "..tostring(NumberOfWLS).." Wls! I will do a wl giveaway now!")
            Bot:setBubble(Bubble.none)
            sleep(750)
            Bot:setBubble(Bubble.talk)
            sleep(1500)
            Bot:say("I have no empathy for you if you did not want them given away.")
            Bot:setBubble(Bubble.none)
            sleep(750)
            Bot.auto_collect = false
           
            for i=1,NumberOfWLS do
              Path = Bot:getPath(Botx+math.random(-10,10),Boty+math.random(-10,10))
              Bot:moveTile(Path)
              sleep(150)
              Bot:fastDrop(Item.id,1)
              sleep(150)
            end
            
            sleep(500)
            Bot:moveTile(Botx,Boty)
            
            Bot:setBubble(Bubble.talk)
            sleep(1500)
            Bot:say("Yippee! Enjoy your giveaway!")
            sleep(100)
            Bot:say("/cheer")
            Bot:setBubble(Bubble.none)
            sleep(2500)
            Bot.auto_collect = true
        end
    end
    sleep(150)
end 

Lua online compiler

Write, Run & Share Lua code online using OneCompiler's Lua online compiler for free. It's one of the robust, feature-rich online compilers for Lua language, running the latest Lua version 5.4. Getting started with the OneCompiler's Lua editor is easy and fast. The editor shows sample boilerplate code when you choose language as Lua and start coding.

Taking inputs (stdin)

OneCompiler's Lua online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Lua program which takes name as input and prints hello message with your name.

name = io.read("*a")
print ("Hello ", name)

About Lua

Lua is a light weight embeddable scripting language which is built on top of C. It is used in almost all kind of applications like games, web applications, mobile applications, image processing etc. It's a very powerful, fast, easy to learn, open-source scripting language.

Syntax help

Variables

  • By default all the variables declared are global variables
  • If the variables are explicitly mentioned as local then they are local variables.
  • Lua is a dynamically typed language and hence only the values will have types not the variables.

Examples

-- global variables
a = 10

-- local variables

local x = 30
Value TypeDescription
numberRepresents numbers
stringRepresents text
nilDifferentiates values whether it has data or not
booleanValue can be either true or false
functionRepresents a sub-routine
userdataRepresents arbitary C data
threadRepresents independent threads of execution.
tableCan hold any value except nil

Loops

1. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition)
do
--code
end

2. Repeat-Until:

Repeat-Until is also used to iterate a set of statements based on a condition. It is very similar to Do-While, it is mostly used when you need to execute the statements atleast once.

repeat
   --code
until( condition )

3. For:

For loop is used to iterate a set of statements based on a condition.

for init,max/min value, increment
do
   --code
end

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increase re-usuability and modularity.

optional_function_scope function function_name( argument1, argument2, argument3........, argumentn)
--code
return params with comma seperated
end