Jump to content

Infinite count?


Akul5

Recommended Posts

So I have:

if (subtraction > 0)
ContainerREF.AddItem Caps001 subtraction
endif

 

I get this:

SCRIPTS: Script 'InfItem', line 12:
Syntax Error. Invalid reference 'ContainerREF' (only object references
and reference variables are allowed in this context).

Link to comment
Share on other sites

[That would probably suffice for the intended purposes. Would there be a way to edit that so the number never climbs above a certain number. For instance, I don't want to take 1 ___ and it add 1000 ___ each time. I would lke to restrict the max quantity of that object, if possible.

 

if (ContainerREF.GetItemCount Ammo308Caliber <= 0 )
 ContainerREF.AddItem Ammo308Caliber 1000
endif

Since the additem amount will only be applied if inventory becomes less than or equal to 0, that will set the max count at 1000. It would save the script the trouble of determining subtractions and incremental changes.

 

ContainerREF was just a generic name placeholder. Any name will do. I prefer to use the hex ref # that is in the upper right corner of the reference window. It seems to be more dependable then relying on user created reference names (i.e. if "010105AD".GetItemCount Ammo308Caliber <= 0 ). The hex reference # would be supplied by the GECK when the container is placed at a location.

 

If you use Begin OnActivate then I think that you would not actually have to stock the container with a starting inventory. The script would check the contents each time it is opened and replenish the inventory as needed, including the first time.

Link to comment
Share on other sites

Thank you, everyone that responded. You helped enormously. I do have another question, though.

 

 

In the RR Companions Vault, there is an armory room (near the Quarters) that includes a set of toolboxes, one for each type of ammo (e.g. 10mm, Alien Power Cells, Mini Nukes, etc.).

 

When I utilize the "ContainerREF" reference, it restricts me to one container for the script. I cannot set two separate containers with the same Reference ID. The "Form ID is not unique." So, I cannot set Reference ID of the 10mm, APC, and Mini Nukes toolboxes as the same.

 

Is there a way to use the same method for several different containers? If not, are there alternative methods that do?

Link to comment
Share on other sites

Yes, there is.

 

I selected an ammo box from the object list: LootAmmoBox308Calliber. I renamed it as: BottomlessAmmoBox308Calliber, to make it into a unique item so that I could add this script to it:

 

scn BottomlessAmmoBoxSCRIPT

ref myself

Begin OnActivate

Activate

set myself to GetSelf

if (myself.GetItemCount Ammo308Caliber <= 0 )
	myself.AddItem Ammo308Caliber 1000
endif
End

 

This uses the GetSelf function rather than a reference ID, so that this box can be selected from the object list and placed anywhere multiple times. If you want the box to deliver more than just 308 ammo, then copy the if thru endif argument and paste it below the first if/endif sequence inside the Begin/End notations, and change the item type and/or amount for each sequence.

 

If you want different boxes to dispense different items then you would need variations of the script for the different boxes.

 

One caveat: since I placed the box ingame with no starting inventory it shows that it is empty when you look at it, It is never empty though when you open it. If you close it without emptying it completely then it doesn't read empty anymore.

 

Tested ingame, works for me.

Link to comment
Share on other sites

Just something to note - this type of thing should never be used in a script:

ref rMySelf
...
set rMySelf to GetSelf
rMySelf.<ReferenceFunction>

When a reference function is called on the scripted reference, it should be called with implicit reference syntax instead:

<ReferenceFunction>

GetSelf should only be used when passing information about a RefID into another script, or when calling functions such as PlaceAtMe.

 

For more information on reference function syntax, have a look at the appropriate section of my Scripting for Beginners tutorial - Reference Functions

 

Cipscis

Link to comment
Share on other sites

Just something to note - this type of thing should never be used in a script:
ref rMySelf
...
set rMySelf to GetSelf
rMySelf.<ReferenceFunction>

When a reference function is called on the scripted reference, it should be called with implicit reference syntax instead:

<ReferenceFunction>

GetSelf should only be used when passing information about a RefID into another script, or when calling functions such as PlaceAtMe.

 

For more information on reference function syntax, have a look at the appropriate section of my Scripting for Beginners tutorial - Reference Functions

 

Cipscis

If I am wrong then mea maxima culpa, but can you explain why I am wrong and how is the above different than this script from your tutorial:

 

Instead, the return value of GetContainer must be stored in a local "ref" variable, and that local variable should be used to call GetContainer:

 

ref rContainer

set rContainer to GetContainer

rContainer.AddItem Caps001 10

In our script, we have already called a reference function - GetContainer. Because GetContainer only really works on inventory items, it should always be called with implicit reference syntax, just like we have done.

 

Also, here is an unedited script from vanilla FO3:

 

scn VintageRadioStartOnSCRIPT

short init
ref mySelf

;**********************************

Begin onLoad

if (init == 0)
	set mySelf to getSelf
	activate mySelf
	set init to 1
endif

End

;**********************************

Begin onActivate
	
activate

End

;**********************************

 

So, why must this never be done and what are the consequences of doing it, please?

Link to comment
Share on other sites

Sorry, I should have clarified a bit. Basically, there is no point whatsoever in storing the return value of GetSelf in a "ref" variable for the purpose of calling a reference function on it in the same script. The reason for this is that reference functions can be called with "implicit reference syntax", meaning that the reference syntax (i.e. the reference specification before the function call) is missing. When this syntax is absent, it is implied that the reference function is called on the scripted reference. For example, the following two examples of code will have the same function, but the first example contains redundant code and will therefore be less efficient:

ref rSelf
...
set rSelf to GetSelf
rSelf.AddItem Ammo308Caliber 1000

AddItem Ammo308Caliber 1000

In that example from my tutorial, I have called reference functions on the return value of GetContainer because I want them to be run on the reference that has the scripted item in its inventory, as opposed to the scripted item itself. Because inventory items can't contain items, if I tried to call AddItem with implicit reference syntax it would have no effect.

 

GetSelf is only really useful under two circumstances:

  • When calling functions such as PushActorAway or Activate that take a RefID as a parameter (as in that example from a vanilla script)
  • When the return value of GetSelf is passed to another script, such as a quest script.

While there are normally no "dangers" involved in using GetSelf, you should be very careful if using it in a script attached to an inventory item. The reason for this is that inventory items aren't assigned RefIDs in the same way as references, so if the return value of GetSelf is utilised in another script it will probably cause a script halt.

 

An interesting fact about GetSelf is that it's a reference function, so if you follow the logic that reference functions can only be called on the scripted reference via explicit reference syntax using the return value of GetSelf, then it follows that GetSelf must be called on the scripted reference in order to attain its return value before it will be possible to call GetSelf on the scripted reference, resulting in a bit of a logical paradox.

 

Sorry if I'm still a little unclear, just let me know if I need to do any more explaining about this.

 

Cipscis

Link to comment
Share on other sites

If I am unclear about what you say it is most likely because of my own lack of familiarity with the terminology that you use. Implicit and explicit references is something that I will need to study, for instance.

 

It seems that you are saying that I included nonessential wording in the bottomless container script, but not that doing so would cause CTDs or melted motherboards. That's a relief.

 

I substituted GetContainer in the place of GetSelf. Both seem to have the same result. Is there an advantage to GetContainer in this instance? Or are you saying that both are unnecessary? Would this then be sufficient?

 

scn BottomlessAmmoBoxSCRIPT

Begin OnActivate

Activate

if GetItemCount Ammo308Caliber <= 0
	AddItem Ammo308Caliber 1000
endif
End

 

Apparently so. I just tried out the above cleaner script and it worked just the same. I'm all for minimalism. Keep it simple. Thanks.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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