Jump to content

Need help with a script


Chemist18

Recommended Posts

I'm new to scripting in Fallout 3, I never played Oblivion or FO1 or FO2. I have however programmed in VBA, FORTRAN, and COBOL (giving up my age).

 

The script I'm working on is for the player house I built. I always accumulate lots of crap as I play. I thought it would be great to have a bin I could throw all the stuff in and make that obnoxious robot sort everything into separate containers.

 

I created a number of uniquely named containers. As an example of the script:

 

Container named 'PlayerJunkDump' with a container named "ContDetergent"

 

Script:

 

Set ItemCount to PlayerJunkDump.GetItemCount BoxDetergent

ContDetergent.Additem BoxDetergent ItemCount

PlayerJunkDump.RemoveItem BoxDetergent ItemCount

 

Set ItemCount to PlayerJunkDump.GetItemCount PilotLight

ContShishkabab.Additem PilotLight ItemCount

PlayerJunkDump.RemoveItem PilotLight ItemCount

 

....

 

Well this worked great when all the boxes were empty. BUT if I put stuff in the box, run the script, everything is fine, then add a second batch of stuff to the junk box, run the script, the only items in the boxes are those from the second batch.

 

So I edited the script to look something like this

 

Script:

 

Set ItemCount to PlayerJunkDump.GetItemCount BoxDetergent

Set ExistingCount to ContDetergent.GetItemCount BoxDetergent

Set TotalCount to ExistingCount + ItemCount

ContDetergent.Additem BoxDetergent TotalCount

PlayerJunkDump.RemoveItem BoxDetergent ItemCount

 

Set ItemCount to PlayerJunkDump.GetItemCount PilotLight

Set ExistingCount to ContShishkabab.GetItemCount PilotLight

Set TotalCount to ExistingCount + ItemCount

ContShishkabab.Additem PilotLight TotalCount

PlayerJunkDump.RemoveItem PilotLight ItemCount

 

Now the stuff just dissappears from the junk box. Will someone help me out with my logic please?

Link to comment
Share on other sites

Those lines would all be indented in groups of 5 as I typed them, however, if these's a style that will enable you to help me more I'll be happy to try it.

 

I usually set up like this

 

Begin GameMode

 

Set Variable1 to Container.GetItemCount ComponentX

Set...

 

Set Variable1 to Container.GetItemCount ComponentY

 

Return

 

End

 

However, essentially my reasoning was this:

 

1) find out how many of an item is in the junk container then add that many to the specific container

I had assumed that .Additem would work the same in scrip as it does in the console, that it would literally add that many MORE items, but it appears to delete the contents then add the new amount.

 

2) so I set up three variable, 1 for number of items in junk box, 1 for the number of items in the specific container, and third to hold the total of the two, then .additem to the container

 

I'm sure it's something very simple that I don't know about scripting for FO3...

Link to comment
Share on other sites

For visibility's sake, code is better seen inside code tags, like this:

Set ItemCount to PlayerJunkDump.GetItemCount BoxDetergent
Set ExistingCount to ContDetergent.GetItemCount BoxDetergent
Set TotalCount to ExistingCount + ItemCount

 

If it's a full code or otherwise contains nesting, then it should also be idented.

Now, as suggestion, strip the code to only 1 item (say, detergent boxes), and use messages to show just how many is it trying to add. If you're using FOSE, printc would make this debug part a lot easier.

Link to comment
Share on other sites

Well I have the script working now and as usual it was something silly and obvious (I think)

 

I had put the script inside 'Begin GameMode' rather than 'OnActivate'. I guess the script shouldn't run 100 times a second. DOH!

 

Not sure why the numbers would change regardless of how frequently the script checks them. Perhaps it was tired and wanted to get back at me for my carelessness? :)

 

Thanks.

Link to comment
Share on other sites

Chemist - yep you dated yourself there with Cobol and Fortran..

 

This house mod you are working on are you going to release it or is it personal only? Reason I ask is I cannot find a suitable house mod not in Megaton that includes a SORTER. I hate sorting manually takes way too long..

 

Thanks

 

JW

Link to comment
Share on other sites

Chemist - yep you dated yourself there with Cobol and Fortran..

 

This house mod you are working on are you going to release it or is it personal only? Reason I ask is I cannot find a suitable house mod not in Megaton that includes a SORTER. I hate sorting manually takes way too long..

 

Thanks

 

JW

 

I currently have a house mod on Nexus, MegatonSuburbHome. Once I'm confident the sorter is fairly robust I can add it to that listing. Right now it's my plan to make the obnoxious robot trigger the script but I may just stick a switch on the wall instead :).

 

It seems to be working okay so far. I'm adding more items to what it will sort.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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