Jump to content

Photo

OnInit question


  • Please log in to reply
3 replies to this topic

#1
greyday01

greyday01

    Fan

  • Premium Member
  • 291 posts

I have an activator spawning random creatures when activated. That part is working ok. But I'm having trouble because I want the first creature in the list to be already spawned before the button is activated. I tried OnInit but it seems to fire twice. when I first enter the cell there are 2 of the creatures I want. Activating the button removes one and replaces that one but leaves the first still in the cell. Without OnInit the cage is empty until activated. I thought of trying OnCellLoad or OnCellAttach to cause the activator to activate itself. That would at least prevent an empty cage, at least if they fired reliably, 

 

Just thought of an idea. Just place  a creature in the cage and have the activator simply disable it.

 

But I would still like to know what is going on with OnInit.



#2
maxarturo

maxarturo

    Faithful poster

  • Members
  • PipPipPipPip
  • 1,727 posts
The "OnInit" will fire twice, one when the game is loaded and one when you enter that cell (where the script is living).
 
One way to handle that "Twice Fired" is to use 'States'.
Example:
 
Auto State Waiting
Event OnInit(...)
           .......Do something
           .......Do something Else
            GoToState("WaitingPlayer")
EndEvent
EndState
 
State WaitingPlayer
Event SomeEvent(....)
           .......Do something
           .......Do something Else
EndEvent
EndState

Edited by maxarturo, 08 July 2020 - 02:27 PM.


#3
greyday01

greyday01

    Fan

  • Premium Member
  • 291 posts

I tried something like that. I got a compile error saying OnInit needed to be in the Empty State  so I removed the whole SetUp State and just had OnInit .

That did not work out.

Anyway it finally works by getting rid of OnInit entirely and just placing a reference and having it disabled and deleted OnActivation.

Sooner or later I might figure out Papyrus. Right now the explanations at CreationKit.com are often rather confusing even with the examples they give.

I really admire those that can make some of the really complicated mods

Thank you for your patience and help for a novice.



#4
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 8,833 posts

You can do it without the state method by registering for an update.  Even tho the OnInit runs twice the update event will only run once as the first wait period will be replaced by the second wait period. Something like:

Event OnInit()
  RegisterForSingleUpdate(5.0) ;five seconds later
EndEvent

Event OnUpdate()
  ;do stuff
EndEvent





Page loaded in: 0.967 seconds