Jump to content

Script check...


Rayek

Recommended Posts

Trying to make a cooking pot and accessories toggle able with and Enable/Disable script. (i.e. click on pot...it disappears and re-appears over the now lit embers)

 

The script returns no errors and the initial Enable/Disable works...but I can't toggle it back and forth.

 

What am I missing? Wrong type of script for this?

Scriptname RE_CookingPotScript extends ObjectReference  

ObjectReference Property BurningEmber Auto
ObjectReference Property DousedEmber Auto
ObjectReference Property FireLight Auto
ObjectReference Property CookingPotOn Auto
ObjectReference Property CookingPotOff Auto

Event OnActivate(ObjectReference akActionRef)
  If akActionRef == Game.GetPlayer()
    BurningEmber.Enable()
    DousedEmber.Disable()
    FireLight.Enable()
    CookingPotOn.Enable()
    CookingPotOff.Disable()
  Else
    BurningEmber.Disable()
    DousedEmber.Enable()
    FireLight.Disable()
    CookingPotOn.Disable()
    CookingPotOff.Enable()

  EndIf
EndEvent

This being my 2nd script attempt...any help is appreciated.

Edited by Rayek
Link to comment
Share on other sites

Try this.

Scriptname RE_CookingPotScript extends ObjectReference
ObjectReference Property BurningEmber Auto
ObjectReference Property DousedEmber Auto
ObjectReference Property FireLight Auto
ObjectReference Property CookingPotOn Auto
ObjectReference Property CookingPotOff Auto
Actor Property PlayerREF Auto
Int IsOn
Event OnActivate(ObjectReference akActionRef)
If (akActionRef == PlayerREF)
TurnOnFire()
EndIf
EndEvent
Function TurnOnFire()
If (IsOn == 0)
IsOn = 1
BurningEmber.Enable()
DousedEmber.Disable()
FireLight.Enable()
CookingPotOn.Enable()
CookingPotOff.Disable()
Elseif (IsOn == 1)
IsOn = 0
BurningEmber.Disable()
DousedEmber.Enable()
FireLight.Disable()
CookingPotOn.Disable()
CookingPotOff.Enable()
Endif
EndFunction
Edited by Di0nysys
Link to comment
Share on other sites

Please post your scripts like this. You were right about getting the playerref at run time, but your script has no way of telling if the pot is on or off. Since this is only yes or no use a bool and there is no reason to check of the bool is true because if it is not false it would have to be true.

Scriptname RE_CookingPotScript extends ObjectReference 


ObjectReference Property BurningEmber Auto
ObjectReference Property DousedEmber Auto
ObjectReference Property FireLight Auto
ObjectReference Property CookingPotOn Auto
ObjectReference Property CookingPotOff Auto
Bool On
 
Event OnActivate(ObjectReference akActionRef)

  If akActionRef == Game.GetPlayer()
  Else
    Return
  EndIf
  
  If On
    BurningEmber.Disable()
    DousedEmber.Enable()
    FireLight.Disable()
    CookingPotOn.Disable()
    CookingPotOff.Enable()
    On = False
    Return
  EndIf

  BurningEmber.Enable()
  DousedEmber.Disable()
  FireLight.Enable()
  CookingPotOn.Enable()
  CookingPotOff.Disable()
  On = True

EndEvent
Edited by Masterofnet
Link to comment
Share on other sites

 

Scriptname RE_CookingPotScript extends ObjectReference

ObjectReference Property BurningEmber Auto
ObjectReference Property DousedEmber Auto
ObjectReference Property FireLight Auto
ObjectReference Property CookingPotOn Auto
ObjectReference Property CookingPotOff Auto

Event OnActivate(ObjectReference akActionRef)

    If akActionRef == Game.GetPlayer()
        If BurningEmber.IsDisabled()
            BurningEmber.Enable()
            DousedEmber.Disable()
            CookingPotOn.Enable()
            CookingPotOff.Disable()
            FireLight.Enable()
        Else
            FireLight.Disable()
            CookingPotOff.Enable()
            CookingPotOn.Disable()
            DousedEmber.Enable()
            BurningEmber.Disable()
        EndIf
    EndIf

EndEvent
Link to comment
Share on other sites

Scriptname RE_CookingPotScript extends ObjectReference

ObjectReference Property BurningEmber Auto
ObjectReference Property DousedEmber Auto
ObjectReference Property FireLight Auto
ObjectReference Property CookingPotOn Auto
ObjectReference Property CookingPotOff Auto

Event OnActivate(ObjectReference akActionRef)

    If akActionRef == Game.GetPlayer()
        If BurningEmber.IsDisabled()
            BurningEmber.Enable()
            DousedEmber.Disable()
            CookingPotOn.Enable()
            CookingPotOff.Disable()
            FireLight.Enable()
        Else
            FireLight.Disable()
            CookingPotOff.Enable()
            CookingPotOn.Disable()
            DousedEmber.Enable()
            BurningEmber.Disable()
        EndIf
    EndIf

EndEvent

 

@ Steve40 I try to write codes, that are has simple & to the point as yours. On reading it all I could think of was, don't use IsEnabled(), it's a function, use IsDisabled() or !IsDisabled() instead. Do you have any idea how long it take me to work stuff like that out, even though I know it? Yes I'm jealous. :laugh:

Edited by PeterMartyr
Link to comment
Share on other sites

 

Scriptname RE_CookingPotScript extends ObjectReference

ObjectReference Property BurningEmber Auto
ObjectReference Property DousedEmber Auto
ObjectReference Property FireLight Auto
ObjectReference Property CookingPotOn Auto
ObjectReference Property CookingPotOff Auto

Event OnActivate(ObjectReference akActionRef)

    If akActionRef == Game.GetPlayer()
        If BurningEmber.IsDisabled()
            BurningEmber.Enable()
            DousedEmber.Disable()
            CookingPotOn.Enable()
            CookingPotOff.Disable()
            FireLight.Enable()
        Else
            FireLight.Disable()
            CookingPotOff.Enable()
            CookingPotOn.Disable()
            DousedEmber.Enable()
            BurningEmber.Disable()
        EndIf
    EndIf

EndEvent

 

@ Steve40 I try to write codes, that are has simple & to the point as yours. On reading it all I could think of was, don't use IsEnabled(), it's a function, use IsDisabled() or !IsDisabled() instead. Do you have any idea how long it take me to work stuff like that out, even though I know it? Yes I'm jealous. :laugh:

 

The difference between the two is that isDisabled is a native function and is faster than isEnabled(which just calls IsDisabled()). Indeed, always go with the native function where possible. I bang my head on the desk everytime someone uses GetActorRef.

Link to comment
Share on other sites

Myself I'd use parent and child done in the render window.

Use 1 xMarker and all your items you want disabled or enabled you set the xMarker as the parent.

Since you can set children to opposite states of the parent it works fast.

 

Then with your activator you set a linked ref to the xmarker.

In your activator script you can use GetLinkedRef() to query the state of the xmarker.

 

No properties needed at all, as less properties is less save bloat.

Also your script is faster over all since it only disables or enables 1 item.

 

 

Scriptname RE_CookingPotScript extends ObjectReference

ObjectReference xMarker
Actor Player

Event OnInit()
    Player = Game.GetPlayer()
    xMarker = Self.GetLinkedRef()
EndEvent

Event OnActivate(ObjectReference akActionRef)
    If akActionRef == Player
        If xMarker.IsDisabled()
            xMarker.Enable()
        Else
            xMarker.Disable()
        EndIf
    EndIf
EndEvent
Edited by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

Yes, When enabling or disabling several object-references using an xmarker is the way to go. In this case you could use one of the object references as the enable parent of the others.

 

Also if I were checking multiple items enabled state I would use a bool. Unless they were linked as you are suggesting.

 

Why are you using OnInit?

Scriptname RE_CookingPot extends ObjectReference

Event OnActivate(ObjectReference A)

  If A == Game.GetPlayer()
  Else
    Return
  EndIf

ObjectReference x = GetLinkedRef()

  If x.IsDisabled()
    x.Enable()
    Return
  EndIf

  x.Disable()

EndEvent
Edited by Masterofnet
Link to comment
Share on other sites

  • Recently Browsing   0 members

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