질문과 답변

Extra Form

@state 라는 해시에 여러 상태이상을 구현하려고 합니다만, 이상하게도 구조적으로 이상한건 느껴지지 않는데 정상적으로 작동되지 않아 여기에 올려봅니다..; ㅡㅜ

 

class Game_Character

 

 

> > initialize


  #State
    @state = {}
    istate = {}
    con  = {}
   
    istate = {
     'time' => 0,
     'degree' => 0}
    
    con  = {
     '출혈' => istate,
     '기절' => istate,
     '독'   => istate,
     '탈진' => istate,
     '다운' => istate,
     '넉백' => istate}
    
    @state = {
     'life' => nil,
     'dead' => nil,
     'con'=> con,
     'con_add'=> con}

 

> > update
     lasc_manager

 

> > lasc_manager    
    #횡스크롤용 방향세팅
    lasc_way
    #각종 State 업데이트
    lasc_state

> >   lasc_state   


      #지속시간 업데이트
        for i in @state['con'].keys
          case
            when @state['con'][i]['time'] > 0
                 @state['con'][i]['time'] -= 1
            when @state['con'][i]['time'] == 0
                if @state['con'][i]['degree'] > 0
                 @state['con'][i]['degree'] = 0
                end
          end
        end
       #정보 업데이트
        for i in @state['con'].keys
          if @state['con_add'][i]['degree'] > 0
            case
              when @state['con'][i]['degree'] > 0
                if @state['con_add'][i]['degree'] > @state['con'][i]['degree']
                  @state['con'][i]['degree'] = @state['con_add'][i]['degree']
                  @state['con'][i]['time'] += @state['con_add'][i]['time']*(
                  @state['con_add'][i]['degree']/((@state['con_add'][i]['degree']+@state['con'][i]['degree'])/2).to_i)

                elsif @state['con_add'][i]['degree'] <= @state['con'][i]['degree']
                  @state['con'][i]['time'] += @state['con_add'][i]['time']*(
                  @state['con'][i]['degree']/((@state['con_add'][i]['degree']+@state['con'][i]['degree'])/2).to_i)
                end
              when @state['con'][i]['degree'] == 0
                @state['con'][i]['time'] = @state['con_add'][i]['time']
                @state['con'][i]['degree'] = @state['con_add'][i]['degree']
                 
            end
            @state['con_add'][i]['degree'] = 0
            @state['con_add'][i]['time'] = 0
          end
        end
      #상태 효과
      case
        #●
        when @state['con']['출혈']['time'] > 0
          @hp -= @state['con']['출혈']['degree']
        #●
        when @state['con']['기절']['time'] > 0
          @active_manage['attack_take'] = false
          @active_manage['move'] = false
          if @state['con']['기절']['time'] <= 1
            @active_manage['attack_take'] = true
            @active_manage['move'] = true
          end
        #●
        when @state['con']['넉백']['time'] > 0
            pn('넉백')
          r = (@way == 'R'? 1 : -1)
                p '4'
          if @way == 'R'# R 6 L 4
            for i in 0..@state['con']['넉백']['degree']
                p 'a'
              if !passable?(@x-i,@y,4)
                moveto(@x-i+1,@y,4)
                p 'o'
                break
              end
            end
          else
            for i in 0..@state['con']['넉백']['degree']
              if !passable?(@x+i,@y,6)
                moveto(@x+i-1,@y,6)
                break
              end
            end
          end
        end

.

.

.

.이런식으로 되어있습니다만, 작동하지 않습니다 ㅠ

 

@state['con_add']['넉백']['time']=200;@state['con_add']['넉백']['degree']=2

라고 해놓으면,  넉백이라는 해시키뿐만 아니라 다른 키들도 전부 위와같은 값으로 바뀌며,

얼마정도 지나면 전부 0으로 되돌아가 버립니다.

 

어느부분이 잘못된건지... 미치겠습니다 ㅠ 저에게 구원의 손길을 ㅠㅠㅠㅠ.........

 

 

Who's Lighna

profile

스트레스 받는다.

Comment '6'
  • ?
    허걱 2012.12.19 20:24

    루비에서 >> 이런 표현이 있었나요?? 아무튼...
    스크립트 전반을 본건 아니지만...
    위에서 @state 내부의
    'con' 과 'con_add' 의 con 을 같은걸로 정해준게 맞는건가요?

    만약 'con' 과 'con_add' 의 con 을 다른 해시로 나타내고 싶었다면 그냥 {} 라고 해주시기 바랍니다.
    해시가 변수에 대입된 후에 'con', 'con_add' 같은 변수에, con 이라는 변수로 대입하려고 하면 새로 생성되는게 아니라 같은 con을 가리키기만 할 뿐입니다. (포인터와 같은 기능입니다.)
    그래서 'con_add' 에서 바꿔주면 'con' 도 바뀐걸 볼 수밖에 없게되죠.

    a = {}
    b = a
    c = a
    했을 때, b, c 는 하나의 a를 공유하게 됩니다.
    (p b.object_id, c.object_id #=> 27491596, 27491596 등과 같이 같은 오브젝트를 나타냄.)

    아마 이 부분 때문에 원하는 결과를 못얻은듯 보여서 일단 한마디 끄적여 봅니다..@_@

  • profile
    Lighna 2012.12.19 20:29
    ........! 그랬군요......이럴수가 ㅠㅠ
  • ?
    허걱 2012.12.19 20:33

    Ruby 언어가 해시 뿐이 아니라 배열이나 클래스등, 여러 변수의 모음이 될 수 있는 구조라면 주소만 할당되는듯 하더군요..@_@;

    필요하다면, object.dup 혹은 object.clone 등을 활용해 보시기 바랍니다.

  • profile
    Lighna 2012.12.19 21:43
    #State
    @state = {}
    istate = []
    con = []

    istate = ['time','degree'}

    con = ['출혈','기절','독','탈진','다운','넉백']

    @state = {
    'life' => nil,
    'dead' => nil,
    'con'=> nil,
    'con_add'=> nil}
    for i in con
    @state['con'][i]={}
    @state['con_add'][i]={}
    end
    for i in con
    for n in istate
    @state['con'][i][n]=0
    @state['con_add'][i][n]=0
    end
    end

    그럼 이렇게하면 위와같은 일은 일어나지 않겠죠..?
  • ?
    허걱 2012.12.19 21:53
    오타는 무시하고... 오류는 잡힐듯 보이네요.
    덤으로 함수를 만들어서 사용하면 더 편리합니다...라고 말하고 싶네요..^^;
  • profile
    Lighna 2012.12.19 22:06
    감사합니다~

List of Articles
종류 분류 제목 글쓴이 날짜 조회 수
공지 묻고 답하기 가이드 습작 2014.06.14 12451
RMXP 스크립트를 main에 붙여넣기 하는건가요 ? 2 포레버아이둔 2013.06.22 607
RMXP 스크립트로 화면상에 해당 변수 띄우는법 알중: 2013.07.05 648
RMXP 스크립트로 픽쳐표시하는법 3 석진이 2011.07.18 2845
RMXP 스크립트로 자동 부분 저장 XP 파일 아직도 있나요? 1 g223k 2013.01.02 651
RMXP 스크립트로 이벤트 생성 3 하베군 2013.03.09 754
RMXP 스크립트로 음악재생시 메뉴를 닫았을 경우 노래를 끄고 싶어요. 1 운운 2013.12.30 843
RMXP 스크립트로 메뉴를 바꿨더니 픽쳐에 묻히네요. 1 모르모트 2012.02.15 2412
RMXP 스크립트관련 질문 1 게이머 2011.01.05 419
RMXP 스크립트가 이상ㅠㅠ 3 나는나다 2010.09.23 967
RMXP 스크립트가 사용이 안됩니다. 16 file 이룩 2014.01.12 900
RMXP 스크립트=정기적병렬처리 이벤트? 3 stonesoup 2012.04.19 3989
RMXP 스크립트 호출로 강제 세이브/로드시키려면? 4 하진 2012.07.02 1595
RMXP 스크립트 해석 부탁드립니다. 1 ssbest1015 2011.05.22 1376
RMXP 스크립트 함수처리(?) 관련 질문 6 Lighna 2012.12.19 641
RMXP 스크립트 하는 방법좀 가르켜 주세요. 스크립트가 머죠? 8 난몰라 2011.12.26 1971
RMXP 스크립트 특정 맵 or 스위치에따라 키고끄게하는법 ㅜㅜ 2 샤르티에 2011.09.14 1498
RMXP 스크립트 충돌..좀 도와주세요...ㅠㅠ.. or반때 2016.04.13 91
RMXP 스크립트 충돌 도와주실 분.. file 아미상 2015.01.13 111
RMXP 스크립트 창에서 한국어폰트를 못읽습니다;; file 석진이 2011.06.05 1209
RMXP 스크립트 질문 .... 3 샤프리드 2010.12.02 518
Board Pagination Prev 1 ... 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 ... 90 Next
/ 90

[개인정보취급방침]