Tutorialspoint

Lua Programming Examples

Fgjhfjdtodykegmdz/÷¥_*%/@€@&$tophdgi.

lua

print("test")PUBG
UI HIM THE NO PIND IND I' POT INDIA IM LOLK IND HET SHOT IND INTANI ikgigtid

Execute Lua Online

lua

math.randomseed(os.time())
local trials = 100
local iter = 1
local targetpercent = 0.99
function recur()
    local tot = 0
    for c = 1, trials do
        local b = false
        local x = 1
        while b == false and x <= iter do
            r = math.random(127)
            if r <= 127 and r > 63 then
                tot = tot + 1
                b = true
            end
            x = x + 1
        end
        
    end
    if tot/trials <= targetpercent then
        iter = iter + 1
        x = 1
        tot = 0
        recur()
    end
end
local totiter = 0
for c = 1, 100 do
    recur()
    totiter = iter + totiter
    iter = 1
end
print (totiter/trials)
print ("588 tier 7, 268 tier 6, 120 tier 5, 58 tier 4, 31 tier 3, 15 tier 2, 7 tier 1")

10-card

lua

math.randomseed(os.time())
local cards={} rev={}
for a=0,77,1 do
    cards[a]=a
    end
for i=0,77,1 do
    r1=math.random(0,77)
    r2=math.random(0,77)
    cards[r1],cards[r2]=cards[r2],cards[r1]
    rev[i]=math.random(0,1)
    end
for i=0,9,1 do
    if cards[i]>21 then
        local suit=(cards[i]-21)//14
        io.write((cards[i]-20-(14*suit)))
        if suit==0 then
            io.write("W")
        elseif suit==1 then
            io.write("C")
        elseif suit==2 then
            io.write("S")
        elseif suit==3 then
            io.write("P")
            end
    else
    io.write("M",cards[i])
    end
    if rev[i]==1 then
    io.write(" R")
    end
    io.write("\n")
end

Execute Lua Online

lua

local c1 = 0
local c2 = 0
local c3 = 0
local c4 = 0
local c5 = 0
local c6 = 0
local c7 = 0
local trials = 1
math.randomseed(os.time())
for c = 1, trials do
    local b1 = false
    local b2 = false
    local b3 = false
    local b4 = false
    local b5 = false
    local b6 = false
    local b7 = false
    local lc = 0
    while b1 ~= true and b2 ~= true and b3 ~= true and b4 ~= true and b5 ~= true and b6 ~= true and b7 ~= true do
        local r = math.random(127)
        if r <= 1 then
            if b7 == false then
                b7 = true
                if lc > c7 then
                    c7 = lc
                end
            end
        end
        if r > 1 and r <= 3 then
            if b6 == false then
                b6 = true
                if lc > c6 then
                    c6 = lc
                end
            end
        end
        if r > 3 and r <= 7 then
            if b5 == false then
                b5 = true
                if lc > c5 then
                    c5 = lc
                end
            end
        end
        if r > 7 and r <= 15 then
            if b4 == false then
                b4 = true
                if lc > c4 then
                    c4 = lc
                end
            end
        end
        if r > 15 and r <= 31 then 
            if b3 == false then
                b3 = true
                if lc > c3 then
                    c3 = lc
                end
            end
        end
        if r > 31 and r <= 63 then 
            if b2 == false then
                b2 = true
                if lc > c2 then
                    c2 = lc
                end
            end
        end
        if r > 63 and r <= 127 then 
            if b1 == false then
                b1 = true
                if lc > c1 then
                    c1 = lc
                end
            end
        end
        lc = lc + 1
    end
end
print(c1)
print(c2)
print(c3)
print(c4)
print(c5)
print(c6)
print(c7)

Test Program

lua

print(12345,'ciao')
print(3456,22225)
print(9999)
io.write(9876," ",4321,"\n")
io.write(5555555)

test

lua

print("test")

Execute Lua Online

lua

`local maxcount = 1`

`if string.find(chess,'11') ~= nil and (string.find(chess,'tp') ~= nil or string.find(chess,'eh') ~= nil) then`

	`chess = string.sub(chess,1,-2)`

	`maxcount = 4`

`end`

`if string.find(chess,'1') ~= nil and (string.find(chess,'tp') ~= nil or string.find(chess,'eh') ~= nil) then`

	`chess = string.sub(chess,1,-2)`

	`maxcount = 2`

`end`

`if string.find(chess,'11') ~= nil then`

	`chess = string.sub(chess,1,-2)`

	`maxcount = 9`

`end`

`if string.find(chess,'1') ~= nil then`

	`chess = string.sub(chess,1,-2)`

	`maxcount = 3`

`end`

`for count = 1,maxcount do`

	`if GameRules:GetGameModeEntity().chess_2_mana[chess] ~= nil then`

		`local cost = GameRules:GetGameModeEntity().chess_2_mana[chess]`

		`table.insert(GameRules:GetGameModeEntity().chess_pool[cost],chess)`

	`end`

`end`

level1.lua

lua

physicsToWorld = 20
theme = "theme1"
joints = {
}
birdCameraData = {
    ipad = {
        bottom = 122.18199920654,
        left = -655.24298095703,
        px = 48.054100036621,
        py = -369.68798828125,
        right = 1953.7199707031,
        screenHeight = 768,
        screenWidth = 1024,
        sx = 0.72799998521805,
        sy = 0.72799998521805,
        top = -897.16101074219
    },
    iphone = {
        bottom = 58.935001373291,
        left = -627.74499511719,
        px = 40.922298431396,
        py = -355.47198486328,
        right = 1921.3100585938,
        screenHeight = 968,
        screenWidth = 1280,
        sx = 0.95712798833847,
        sy = 0.95712798833847,
        top = -861.15100097656
    },
    version = "0.02"
}
castleCameraData = {
    ipad = {
        bottom = 122.18199920654,
        left = 547.12298583984,
        px = 1250.4200439453,
        py = -405.29098510742,
        right = 1953.7199707031,
        screenHeight = 768,
        screenWidth = 1024,
        sx = 0.72799998521805,
        sy = 0.72799998521805,
        top = -932.76397705078
    },
    iphone = {
        bottom = 47.576000213623,
        left = 583.97302246094,
        px = 1245.1300048828,
        py = -452.42401123047,
        right = 1906.2900390625,
        screenHeight = 968,
        screenWidth = 1280,
        sx = 0.96799999475479,
        sy = 0.96799999475479,
        top = -952.42401123047
    },
    version = "0.02"
}
counts = {
    RedBird = 1,
    YellowBird = 1,
    WoodBlock9 = 2,
    KingPiglette = 1,
    BlackBird = 1,
    BoomerangBird = 1
}
world = {
    ground = {
        angle = 0,
        definition = "Ground",
        name = "ground",
        x = 55.188701629639,
        y = 5
    },
    RedBird_1 = {
        x = -35.44444444444444,
        y = -1.3333333333333357,
        name = "RedBird_1",
        definition = "RedBird",
        angle = 0
    },
    YellowBird_1 = {
        x = -32.66666666666667,
        y = -1.4444444444444429,
        name = "YellowBird_1",
        definition = "YellowBird",
        angle = 0
    },
    WoodBlock9_1 = {
        x = 62.111111111111114,
        y = -2.1111111111111143,
        name = "WoodBlock9_1",
        definition = "WoodBlock9",
        angle = 0
    },
    WoodBlock9_2 = {
        x = 62.111111111111114,
        y = -6.111111111111107,
        name = "WoodBlock9_2",
        definition = "WoodBlock9",
        angle = 0
    },
    KingPiglette_1 = {
        x = 62.22222222222222,
        y = -11.666666666666664,
        name = "KingPiglette_1",
        definition = "KingPiglette",
        angle = 0
    },
    BlackBird_1 = {
        x = -39.333333333333336,
        y = -1,
        name = "BlackBird_1",
        definition = "BlackBird",
        angle = 0
    },
    BoomerangBird_1 = {
        x = -44,
        y = -2.3333333333333357,
        name = "BoomerangBird_1",
        definition = "BoomerangBird",
        angle = 0
    }
}

Execute Lua Online

lua

print ('What is your name sir?')
    
    name = io.read()
    
    print ('Welcome to the Ride ' ,name)
    
    print ('                                                                                                                                                                                                        ')
    print ('Do you want to join us on our Journey to Assention?')
     print ('                                                                                                                                                                                                        ')
    
    choice1 = io.read() 
    

    if choice1 ==yes then
         print ('                                                                                                                                                                                                        ')
        print ('That is good to hear!!!')
        
        else 
             print ('                                                                                                                                                                                                        ')
            print ('Trust me, it will be tons of fun!')
            
            end
            
            choice2 = io.read() 
             print ('                                                                                                                                                                                                        ')
        print ('Come on it will be heaps of fun dude, just trust me',name )
        
        if choice2 == Yes then
             print ('                                                                                                                                                                                                        ')
            print ('That is good to hear!!!')
            
            else  print ('                                                                                                                                                                                                        ')
                print ('You really have no choice. Sorry I had to do this but the fate of the cult depends on this')
                 print ('                                                                                                                                                                                                        ')
                
                print ('You are hit by the speaker and slump into sleep')
                end
                
                strike = 0
                
                strike = strike +1 
                
            print ('You wake up in a dark, rank building. You have never seen this place before and you hear the maddened raving of crazy people It looks abandoned and un used for a long time')
             print ('                                                                                                                                                                                                        ')
             print ('If you want to get up, type 1 , to play dead, type 2 , to make like a tree and leave, press 3') 
                
                choice3 = io.read("*n") 
                
                if choice3 == 1 then 
                    print (" You get up and stagger over to the door of the building. You see flickering shadows of what seem to be dancing humanoids, mabye you can figure out what happened from them?")
                 print ('                                                                                                                                                                                                        ')
                 end
                
                if choice3 == 2 then 
                    
                    print ('You lie down, waiting, and hoping for someone to find you. It is very wet and under further observation you see that your fore-arms are red. People died here')
                     print ('                                                                                                                                                                                                        ')
                     end
                     
                     
                     if choice3 == 3 then
                         
                         print ('You leap up and sprint over to the broken window. You hear the panicked shouts of people, you cut your arms trying to bust through the glass and you feel something sharp stab you in your back. A thin, frail man with insantiy in his eyes stabs you. You feel yourself getting weaker as you slump down onto the floor')
                         
                          print ('                                                                                                                                                                                                        ') 
                         
                          print ('You died!')
                         
                         end
                          
                          cultpan = 0
                          cultpan = cultpan + 1
                          
                          choice4 = io.read()
                          
                          
                          
                          

Execute Lua Online

lua

print ('What is your name sir?')
    
    name = io.read()
    
    print ('Welcome to the Ride ',name)
    print ('Do you want to join us on our Journey to Assention?')
    
    choice1 = io.read() 
    
    if choice1 ==yes then
        print ('That is good to hear!!!')
        
        else 
            print ('Trust me, it will be tons of fun!')
            
            end
            
            choice2 = io.read() 
            
        print ('Come on it will be heaps of fun dude, just trust me',name )
        
        if choice2 == yes then
            print ('That is good to hear!!!')
            
            else 
                print ('You really have no choice. Sorry I had to do this but the fate of the cult depends on this')
                
                print ('You are hit by the speaker and slump into sleep')
                end
                
                strike = 0
                
                strike = strike +1
                
                
    

1 2 3 4 5 6 7 ... 27 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.