Jump to content

need help with DeleteReference


Alaitur59

Recommended Posts

Hi,
I'm working on my own companions script. My companions are using bedroll to sleep. I want to destroy the references of bedrolls when they are not needed anymore. Looking around the web, it seems the function to do that is DeleteReference. But how ? because I tried several ways, none worked as I expected. In this post : http://forums.nexusmods.com/index.php?/topic/436985-persistent-reference-question/?p=12674498 it is said that disabling and deleting cant be done in the same frame.

here is an example of what I'm doing...

scn TimeToBed

ref bed
short state
short button

Begin OnEquip
  set state to 1
End

Begin GameMode
  if ( state == 1)
    messageboxex "TITLE|place|disable|enable|delete"
    set state to 2
  endif


  if (state == 2)
    set button to getButtonPressed
    if ( button == 0)
      set bed to player.placeatme BedrollSideEntry
      set state to 3
    endif
    if ( button == 1)
      bed.disable
      set state to 3
    endif
    if ( button == 2)
      bed.enable
      set state to 3
    endif
    if ( button == 3)
      bed.DeleteReference
      set state to 3
    endif
  endif

End

so after placeatme a bedroll, I disable it. the bedroll disapears of the screen, then I delete, for me deletereference should be called on a disabled reference at least the one frame after being disabled. But if I enable the reference, I see the bedroll on the screen...
I also save the game after deltrefecnce was called, and reload, the bedroll is still here if I enable it...

Edited by Alaitur59
Link to comment
Share on other sites

You are checking the button pressed in the same frame as the MessageBox

 

Check the button if the state is 1 ( "elseif state == 1" just after the MessageBox line should do).

And "set state to 2" after each "if button ...", to end the cycle.

Link to comment
Share on other sites

[EDIT] Although the crossed text below is true, it is not relevant

 

There seems to be a bug in DeleteReference: if you use as "let i := someref.DeleteReference", it works, but without saving the return value (like just "someref.DeleteReference") it does not.

 

I will report it to the OBSE team.

 

Must be something else in the code, because DeleteReference works under those conditions

[EDIT] Found it: 'bed' is not a valid EditorID. The game must have something named bed elsewhere.

 

This code works - after pressing numpad 1,2,3 in sequence, pressing num0 gives an error because 'bed' is not a valid reference anymore.

   if OnKeyDown 79   ;  NUM1
      let refBed := playerref.placeatme refBedrollSideEntry 1
               printc "placeatme: %i %n  "  refBed refBed          
               let i := refBed.GetDisabled
               printc  "GetDisabled: %g  "  i
               let i := IsFormValid refBed 
               printc  "IsFormValid: %g  "  i
   elseif OnKeyDown 80   ;  NUM2
      refBed.Disable 
               printc "Disabled: %i %n  "  refBed refBed          
               let i := refBed.GetDisabled
               printc  "GetDisabled: %g  "  i
               let i := IsFormValid refBed 
               printc  "IsFormValid: %g  "  i
   elseif OnKeyDown 81   ;  NUM3
      let i := refBed.DeleteReference
               printc "Disabled: %i %n  "  refBed refBed          
               let i := refBed.GetDisabled
               printc  "GetDisabled: %g  "  i
               let i := IsFormValid refBed 
               printc  "IsFormValid: %g  "  i
   elseif OnKeyDown   82   ;  NUM0
      refBed.enable                
               printc "Enabled: %i %n  "  refBed refBed          
               let i := refBed.GetDisabled
               printc  "GetDisabled: %g  "  i
               let i := IsFormValid refBed 
               printc  "IsFormValid: %g  "  i
   endif
Edited by QQuix
Link to comment
Share on other sites

Hi QQuix thanks for reporting that bug, I'm a coder (mostly C++) myself (linux platform only). I expected that is a bug... but because is scripting not coding I don't know how to get some clue of a bug. Scripting languages have sometime, by nature, some strange behaviour...

 

thanks for your code, I use something similar and it works now. Also thanks again because in the same row you teached me how to use my numpad, what I plan to use to give battle order faster.

 

about swissroll bedroll, In order to don't use to much placeAtMe/deleteReference I plan to create one per companion when a companion is enlisted, enabling it when needed / disabling it when not needed and destroying it only when the companion leave my army (alive or dead).

Link to comment
Share on other sites

actually it's very versatile!!!

 

I switch the orders following/waiting for a companion by aiming it and pressing "/". I plan to use different orders in case I have my weapon drawn or not... looks very promising. Now I, starting to set a target to attack for a companion previosly selected ...

Edited by Alaitur59
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...