2024-06-10|閱讀時間 ‧ 約 22 分鐘

[Lua] User Input & Tables表格

    1. io.read()函數,讀入使用者輸入的字串
    raw-image


    1. Tables

    在Lua中,Table 可以包含任何型態的資料

    Tables

    Tables

    1. 可以另外設其他變數來代表數字
    1. table.insert()、table.remove()

    table.insert(nums,19) : 在nums table最後面插入一個19的數字

    table.insert(nums,2,4) : 在nums table的第2個index加入4的數字

    table.remove(nums,4) : 移除在nums table的第4個index的數字

    1. pairs() key value

    key : index

    value : 值

    1. 用for迴圈印出多維的table
    1. concat()

    可以用concat()來連接table裡面的元素

    concat

    concat

    1. table也可以當字典來做使用

    如果依照之前在table當中存入資料的方式,可能會無法知道這個數字和字串分別代表甚麼? 這時候就可以用字典的方式來去做存資料的動作,讓資料庫可以更清楚明瞭。




    分享至
    成為作者繼續創作的動力吧!
    這裡會放一些Lua的筆記
    從 Google News 追蹤更多 vocus 的最新精選內容從 Google News 追蹤更多 vocus 的最新精選內容

    Youna's Devlog 的其他內容

    發表回應

    成為會員 後即可發表留言
    © 2024 vocus All rights reserved.