비주얼노벨 강좌

lua의 파일을 데이터 구조로 사용하기 위해서 table을 사용할려고 했다.

 

책을 제대로 보지 못하고 했는지 모르지만.. ^^ 암튼 처음 할려니 어렵다.

그래서 아래와 같이 설정해봤다.

 

resid = {} --테이블을 설정

 

//방법1

resid[1].id = 10

 

//방법2

resid.id = 10

 

//방법3

function ResIDInit()
 --배열을 초기화 할려면 여기서 for문을 돌려야 한다. 
 for indx = 1, ResIDCount do
  resid[indx] = {}
 end
end

 

-----------------------------------------------

결과

> 방법1

   - 이 부분은 에러가 난다. print()를 해도 값이 없다고 나온다.

> 방법2

   - 이 부분은 에러가 나지 않는다. 정상 동작 한다. 하지만 resid는 배열이 아니라

     단순한 구조체 방법을 취하고 있다. 그래서 resid[1].id 이런건 되지 않는다.

> 방법3

   - 이 부분이 정답이다. table을 만들고 그 테이블이 배열구조를 가지게 할려면

     초기화를 해줘야 한다.

 

------------------------------------------------

참조할 코드

--=======================================
-- function:  EnemyInit()
-- author:    Nick Carlson
-- created:   February 11, 2005
-- returns:   nothing (process)
-- descrip:   sets up initial enemies
--=======================================
function EnemyInit()
    enemyCount = 5 --Number of enemies in the game
    myEnemies = {} --Creates myEnemies table

    --Creates table, one entry per potential enemy
    for indx = 1,enemyCount do
        --Creates a table to hold the data for each enemy
        myEnemies[indx] = {}
        --Now initialize the enemy
        EnemyRespawn(indx)
    end
end


--=======================================
-- function:  EnemyRespawn(indx)
-- author:    Nick Carlson
-- created:   February 11, 2005
-- returns:   nothing (process)
-- descrip:   fills in enemy data given an index to the myEnemies table
--=======================================
function EnemyRespawn(indx)
--Fills/refills myEnemies table according to indx
--indx is the myEnemies table index assigned to the enemy

    --Initial values
    myEnemies[indx].XTHRUST = 0 --Thrust along the x-axis (#)
    myEnemies[indx].YTHRUST = 0 --Thrust along the y-axis (#)
    myEnemies[indx].ROT = math.random(1,8) --Rotation of enemy ship (#)
    myEnemies[indx].ID = GUI_RUNTIME_SPRITES + indx + 100 --Starts GUI identification at 101 (#)
    myEnemies[indx].E_TOW = "no" --Towing flag (target ID # or "no")
    myEnemies[indx].FIRE = 0 --Projectile firing time interval (#)

    --Randomly selects side of screen to enter from
    entrySide = math.random(1,4)
    if entrySide == 1 then       --Left
        myEnemies[indx].EX = math.random(-40,-20) --X coordinate (#)
        myEnemies[indx].EY = math.random(-40,620) --Y coordinate (#)
    elseif entrySide == 2 then   --Right
        myEnemies[indx].EX = math.random(800,820) --X coordinate (#)
        myEnemies[indx].EY = math.random(-40,620) --Y coordinate (#)
    elseif entrySide == 3 then   --Top
        myEnemies[indx].EX = math.random(-40,820) --X coordinate (#)
        myEnemies[indx].EY = math.random(-40,-20) --Y coordinate (#)
    else                        --Bottom
        myEnemies[indx].EX = math.random(-40,820) --X coordinate (#)
        myEnemies[indx].EY = math.random(600,620) --Y coordinate (#)
    end

    --Determines enemy's thrust, reaction, and firing abilities based on time
    --Reaction time decreases as REACT decreases (must be at least 1)
    --Maximum thrust increases as MAX increases
    --enemyFireInterval (#) compared to FIRE to determine enemy shooting (see EnemyFacing(indx) function)
    if (timeCounter >= 0) and (timeCounter < 100) then
        myEnemies[indx].REACT = 5 --Reaction time interval (#)
        myEnemies[indx].MAX = 5 --Maximum thrust (#)
        enemyFireInterval = 9
    elseif (timeCounter >= 100) and (timeCounter < 200) then
        myEnemies[indx].REACT = 4 --Reaction time interval (#)
        myEnemies[indx].MAX = 6 --Maximum thrust (#)
        enemyFireInterval = 8
    elseif (timeCounter >= 200) and (timeCounter < 300) then
        myEnemies[indx].REACT = 3 --Reaction time interval (#)
        myEnemies[indx].MAX = 7 --Maximum thrust (#)
        enemyFireInterval = 7
    elseif (timeCounter >= 300) and (timeCounter < 400) then
        myEnemies[indx].REACT = 2 --Reaction time interval (#)
        myEnemies[indx].MAX = 8 --Maximum thrust (#)
        enemyFireInterval = 6
    elseif (timeCounter >= 400) then
        myEnemies[indx].REACT = 1 --Reaction time interval (#)
        myEnemies[indx].MAX = 9 --Maximum thrust (#)
        enemyFireInterval = 5
    end

    --Randomly selects the AI type and diplays the proper ship image
    myEnemies[indx].TYPE = math.random(1,4) --AI type (1,2,3, or 4)
    if myEnemies[indx].TYPE == 1 then
        CreateItem(myEnemies[indx].ID, "Sprite", "e1_ship1.bmp")
    elseif myEnemies[indx].TYPE == 2 then
        CreateItem(myEnemies[indx].ID, "Sprite", "e2_ship1.bmp")
    elseif myEnemies[indx].TYPE == 3 then
        myEnemies[indx].MAX = 10
        CreateItem(myEnemies[indx].ID, "Sprite", "e3_ship1.bmp")
    elseif myEnemies[indx].TYPE == 4 then
        CreateItem(myEnemies[indx].ID, "Sprite", "e4_ship1.bmp")
    end
    SetItemPosition(myEnemies[indx].ID, myEnemies[indx].EX, myEnemies[indx].EY, 20, 20)
end

Comment '3'

List of Articles
분류 제목 글쓴이 날짜 조회 수
Ren'Py 렌파이 관련 유용한 링크 모음 3 file 습작 2012.12.02 17571
Nekonovel 네코노벨 관련 유용한 링크 모음 1 file 습작 2012.11.19 11944
Neko:Lua 마인크래프트에서 루아언어를 써 Boa요! 2 철쭉 2012.07.21 4183
Neko:Lua Lua for Windows 1 루아마당 2010.08.08 5555
Neko:Lua LUA 란 무엇인가? 6 루아마당 2010.08.08 7224
Neko:Lua 루아의 메모리 관리 방식 루아마당 2010.08.08 5471
Neko:Lua 루아 스크립트를 1 무뇌인 2010.04.20 5923
Neko:Lua 비쥬얼 C++에 루아 연동시키기- file Saber 2010.01.02 7976
Neko:Lua 좀비서바이벌 1.11b 버전 Lua 스크립트 16 판져중위 2009.11.30 9279
Neko:Lua 루아에 잘못 알고계신분이 있는거 같아서 몇줄 적습니다. 16 코르뉴 2009.09.25 8081
Neko:Lua 루아가뭔가요 10 영웅 2009.09.24 6176
Neko:Lua 루아스크립트란 무엇인가? 9 행운 2009.06.11 8444
Neko:Lua 루아가 뭐죠? 11 sooe 2009.06.09 7203
Neko:Lua 루아에 대하여 궁금한점 18 아하!잘봤어요. 2009.05.04 7138
Neko:Lua 루아의 재미있는 기능! 15 엠피군 2009.01.18 7675
Neko:Lua 루아 스크립트 기초 강좌 2부 5 백호 2009.01.12 7755
Neko:Lua 루아 스크립트 기초 강좌 1부 6 백호 2009.01.12 13616
Neko:Lua Lua 시작 [펌] 6 나뚜루 2009.01.10 7431
Neko:Lua lua table 사용방법 - 개인적으로 배우고 있는것. [펌] 3 나뚜루 2009.01.10 7556
Neko:Lua 3부. 변수 - 3.2 문자열 6 Mania 2009.01.10 5464
Neko:Lua 3부. 변수 - 3.1 숫자 4 Mania 2009.01.10 5284
Neko:Lua 2부. 데이터 타입 3 Mania 2009.01.10 6257
Board Pagination Prev 1 2 Next
/ 2