2013-03-26 57 views
0

我有多個Steam帳戶,我想通過具有我指定選項的單個Lua腳本啓動。除了使用提供的代碼啓動之外,我幾乎可以對所有內容進行排序。我不知道如何用這種格式「傳遞」變量。os.execute變量

function Steam(n, opt1, opt2, opt3) 
os.execute[["start C:\Program" "Files\Sandboxie\Start.exe /box:Steam2 D:\Steam\steam.exe -login username password -opt1 -opt2 -opt3"]] 
end 

我有我的用戶名和沙箱的設置使得只有數量需要改變(fenriros2,fenriros3,Steam2,Steam3等)使用相同的密碼。

基本上,我想要這個;

Steam(3, -tf, -exit, -textmode) 

要做;

os.execute[["start C:\Program" "Files\Sandboxie\Start.exe /box:Steam3 D:\Steam\steam.exe -login fenriros3 password -applaunch 440 -textmode"]] 

我會在完成後使用-exit關閉lua窗口。

我意識到我的代碼並不完全有效,但這是以後的一個擔心。現在我只需要讓它工作。

任何幫助都非常感謝,我很抱歉如果我錯過了一些明顯的東西,我在Lua還是比較新的。

+1

你真的問如何把一個串起來,在Lua?或者如何將整數轉換爲字符串? –

+0

我在問我如何在我的配置中將變量放在os.execute中。如果這是不允許的,讓我知道,我會刪除這個。 – Fenri

+0

'os.execute'帶*字符串*。因此,你問如何獲取一個字符串,並將一個或多個變量的值粘貼到某個位置的字符串中。 –

回答

2

首先明顯的一個。 [[]]對字符串進行分隔,因此您只需爲字符串創建一個變量並根據需要替換內容即可。

function Steam(n, opt1, opt2, opt3) 
-- Set up execute string with placeholders for the parameters. 
local strExecute = [["start C:\Program" "Files\Sandboxie\Start.exe /box:Steam{n} D:\Steam\steam.exe -login fenriros{n} password -{opt1} -{opt2} -{opt3}"]] 

-- Use gsub to replace the parameters 
-- You could just concat the string but I find it easier to work this way. 
strExecute = strExecute:gsub('{n}',n) 
strExecute = strExecute:gsub('{opt1}',opt1:gsub('%%','%%%%')) 
strExecute = strExecute:gsub('{opt2}',opt2:gsub('%%','%%%%')) 
strExecute = strExecute:gsub('{opt3}',opt3:gsub('%%','%%%%')) 
os.execute(strExecute) 
end 

Steam(1,'r1','r2','r3') 
+0

謝謝你,併爲此而浪費你的時間道歉。我不知何故知道我在蠢事上磕磕絆絆。無論如何,我非常感謝你的回覆! – Fenri