Jump to content

Script Help: Check if item's in container then get it


Zorkaz

Recommended Posts

The setup:

Codsworth takes care of prewar sanctuary but runs out of fuel (Dies). When you put fuel in a container(Handybox) he starts working again.

 

 

The script, which runs on an xmarker

 

Event onload()
While self.isenabled()

Random = utility.randomint(1,300)
Utility.wait(12)

if random >1
If DS03HandyBox.GetItemCount(DS03Fuel) >0
DS03HandyBox.RemoveItem(DS03Fuel, 1)
DS03Codsworth.Resurrect()
Endif

Elseif random ==1
If DS03HandyBox.GetItemCount(DS03Fuel) >0
DS03HandyBox.RemoveItem(DS03Fuel, 1)
DS03Codsworth.Resurrect()

Elseif DS03HandyBox.GetItemCount(DS03Fuel) == 0
DS03Codsworth.killsilent()
endif
endif
Endwhile
Endevent

 

It's the last script piece of 40, would be nice if anyone had a hint where I went wrong.

Link to comment
Share on other sites

The ElseIf logic does not hold as the zero fuel condition will never trigger.

 

Imagine an If evaluation tree is only passed through once and as soon as a match is found processing stops. Your first 2 random number evaluations will always trigger as the cover all of the number cases, so the third no fuel case will never be picked.

 

Try this (which shows your random number thing isn't actually doing anything);


If (DS03HandyBox.GetItemCount(DS03Fuel) == 0) ; random number does not matter, there is no fuel 
   DS03Codsworth.killsilent()

ElseIf (random == 1) ; we know there is fuel as it passed the first test 
   DS03HandyBox.RemoveItem(DS03Fuel, 1)
   DS03Codsworth.Resurrect() ;is the actor actually dead here, or does that need a test ?

Else ; we know it has fuel and the random number must be more than one 
   DS03HandyBox.RemoveItem(DS03Fuel, 1) ; this case looks the same as = 1, but whatever the designer wants.
   DS03Codsworth.Resurrect()

EndIf
Link to comment
Share on other sites

  • Recently Browsing   0 members

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