﻿ Numstrat - Stumbling into Lua
22 May, 2013, 20:22:18
 OmnomIRC You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

 Pages: [1] 2   Go Down
 Author Topic: Numstrat - Stumbling into Lua -  (Read 1696 times) 0 Members and 1 Guest are viewing this topic.
someone
LV3 Member (Next: 100)

Offline

Gender:
Date Registered: 12 January, 2012, 19:07:23
Posts: 48

Total Post Ratings: +9

 « on: 05 April, 2012, 02:52:28 » +1

I redefined some variables, I think is more legible this way:

 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 --[[Things to do:Declare variables first within a functionMake things more fun and complexPoints System:OLD: Atk -{1,2,3} +{4,5} Def +{1,2,3} -{4,5}NEW: Atk -{4,5} +{4,5} Def +{1,2,3} -{1,2,3}Any better ways? Maybe make Atk more risky, so it's less about luck]]--chance = { [-1] = "",            [0] = "unsuccessful . -",            [1] = "successful . +" }action = { nothing="", attack="Attack", defense="Defense"}function initialize_variables()    v = 0    t = 0    r1 = 0    r2 = -1    state = action.nothingend--function on.create()initialize_variables()--endfunction on.paint(gc)    gc:setFont("sansserif","r",11)    gc:setColorRGB(0,0,0)       gc:drawString("[A]tk or [D]ef?    [R]eset",10,10,"top")    gc:drawString(v,10,30,"top")    if state == action.attack then        gc:drawString("Attack was "  .. chance[r2] .. r1, 10, 50, "top")    elseif state == action.defense then        gc:drawString("Defense was " .. chance[r2] .. r1, 10, 50, "top")    end    gc:drawString("Turn " .. t,200,10,"top")    if v~=0 or t~=0 then        gc:drawString("Average " .. round(v/t,2), 200, 30, "top")    end    gc:setFont("sansserif","r",8)    gc:drawString("Numstrat - Jason Ho",10,200,"top")endfunction on.charIn(ch)    if ch=="a" then        state = action.attack        r1=math.random(4,5)        r2=math.random(0,1)        if r2==1 then            v=v+r1        else    --if r2==0 then            v=v-r1        end        t=t+1    end    elseif ch=="d" then        state = action.defense        r1=math.random(1,3)        r2=math.random(0,1)        if r2==1 then            v=v+r1        else    --if r2==0 then            v=v-r1        end        state=action.defense        t=t+1    end    elseif ch=="r" then        initialize_variables()    end    platform.window:invalidate()endfunction round(value, digits)    return string.format("%." .. digits .. "f", value)end
 « Last Edit: 08 April, 2012, 20:22:41 by someone » Logged
 Pages: [1] 2   Go Up

Page created in 0.218 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.