비주얼노벨 강좌

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 17599
Nekonovel 네코노벨 관련 유용한 링크 모음 1 file 습작 2012.11.19 11967
Vasilriot 해상도 조절에 관한 간단한 고찰 2 하늘바라KSND 2013.05.18 3139
Visual Novel Maker 한글 텍스트 입력 file 러닝은빛 2017.11.21 1443
피니엔진 피니엔진 타이틀 만들기 예제(구버전) 1 file 하늘바라KSND 2015.01.27 1770
피니엔진 텍스트, 대화, 독백 명령어 하늘바라KSND 2014.12.21 1567
피니엔진 타이틀+클릭메뉴 예제 file 하늘바라KSND 2015.07.11 1102
Neko:Lua 좀비서바이벌 1.11b 버전 Lua 스크립트 16 판져중위 2009.11.30 9285
기타 제작툴 소개 : Novelty란 무엇인가? 4 file 습작 2013.05.09 4559
기타 제작툴 소개 : LiveMaker란 무엇인가? 4 file 습작 2013.05.09 8701
Vasilriot 장면 전환할 때 사용할 '장막효과'를 구현해보자. 하늘바라KSND 2013.05.09 2705
피니엔진 애니메이션-스프라이트 간단한 팁 몇가지 하늘바라KSND 2015.07.11 1288
피니엔진 안드로이드로 배포판을 만들기 위해 필요한 것들 하늘바라KSND 2014.12.20 1522
Neko:기타 쓰레드에 '대기' 명령어를 넣었을 때 나타날 수 있는 현상 file 하늘바라KSND 2014.11.27 1024
VNAP 선택지 발생 3 file FNS키리토 2015.01.11 2013
Neko:Lua 비쥬얼 C++에 루아 연동시키기- file Saber 2010.01.02 7977
기타 비주얼 노벨을 처음 제작하시는 분들께 1 file FNS키리토 2015.01.11 13766
Vasilriot 바실리어트의 최신 버전 file 하늘바라KSND 2013.05.11 3989
Vasilriot 바실리어트에서 지원하는 vr팩. 언팩이 가능할까? 하늘바라KSND 2013.05.11 2650
Vasilriot 바실리어트 스크립트 정리하기. file 하늘바라KSND 2012.11.10 3508
Vasilriot 바실리어트 사용할 때 조심해야 할 것 :: 글자수 제한(명령어 오류)(2013.05.15수정) file 하늘바라KSND 2013.05.09 2750
Vasilriot 바실리어트 버튼 사용하기 file 하늘바라KSND 2012.12.21 3163
Board Pagination Prev 1 2 3 Next
/ 3