Jump to content

Script help


Recommended Posts

Having a little issue with a mod script I made a while back. Due to some issues I had to use a backup of it, but it's not quite working. The script is for making a treasury that, when it hits certain amounts, makes it slowly fill with treasure. Right now though, it's not filling with jack squat. Not sure what's really wrong, it saved fine, and all of the object references are connected.

Here's the script:

  Reveal hidden contents

EDIT: I completely forgot to mention this is on Skyrim AE. IDK if that will help with solving, but I thought i'd bring it up.

Edited by wilwhitt56
Link to comment
Share on other sites

The most likely problem is that your properties are not filled.

Also, the OnItemAdded and OnItemRemoved events are only garanteed to fire when going from 0 to not 0, and the converse.  They often don't fire when adding items of a type already present in the container.  If there is some other event you can use as a trigger, that may be helpful.  In any case, adding debugging output will help clarify the actual behavior.

Otherwise...

Function ValueChange should have an else part to the if:

int Function ValueChange(Form akBaseItem, int aiItemCount)
	{Returns the value change from moving [aiItemCount] of [akBaseItem]}
	If akBaseItem==gold001
		Debug.notification( "Detected value change: " + aiItemCount)
		return aiItemCount
	Else
		Debug.notification( "No value change for: " + akBaseItem.getName())
		return 0
	EndIf
EndFunction

You should probably use "else" instead of "elseif <condition>" in your other two functions.

 

Link to comment
Share on other sites

You have a local form variable labeled gold001.  While this is the editor ID name of the gold item, there is no actual data assigned to this variable.  In essence, you are comparing a passed in item to nothing.  This will fail to increase your count which in turn causes your script to do nothing.  Change it from a local form variable to a MiscObject property and assign the correct item to it.  This should allow the rest of the script to continue processing.

Furthermore, a dual array approach may be best here.  By using arrays, you can work with more items with less code.  I've adapted your script to use arrays built at run time so that no changes to already assigned properties needs to be done.  That said, array properties would be an even cleaner approach.

  Reveal hidden contents

 

Link to comment
Share on other sites

  On 3/22/2024 at 12:51 AM, IsharaMeradin said:

You have a local form variable labeled gold001.  While this is the editor ID name of the gold item, there is no actual data assigned to this variable.  In essence, you are comparing a passed in item to nothing.  This will fail to increase your count which in turn causes your script to do nothing.  Change it from a local form variable to a MiscObject property and assign the correct item to it.  This should allow the rest of the script to continue processing.

Furthermore, a dual array approach may be best here.  By using arrays, you can work with more items with less code.  I've adapted your script to use arrays built at run time so that no changes to already assigned properties needs to be done.  That said, array properties would be an even cleaner approach.

  Reveal hidden contents

 

Expand  

I tried to use your script and it lit up with errors like crazy. 

all of the errors are saying:

-only arrays can be indexed

-variable MaxValue is undefined

 -type mismatch while assigning to a none (cast missing or types unrelated)

-none is not a known user-defined type

Link to comment
Share on other sites

Sorry, this is what happens when using an existing example that is unfortunately spread out on a fairly large script.  I forget the inital declarations for the arrays.

Add this to the empty state (i.e. with the properties)

ObjectReference[] VaultLoot
Int[] MaxValue

 

Add those two lines and the script will compile without error.  You'll need to test for proper function.

Link to comment
Share on other sites

  On 3/22/2024 at 11:59 AM, IsharaMeradin said:

Sorry, this is what happens when using an existing example that is unfortunately spread out on a fairly large script.  I forget the inital declarations for the arrays.

Add this to the empty state (i.e. with the properties)

ObjectReference[] VaultLoot
Int[] MaxValue

 

Add those two lines and the script will compile without error.  You'll need to test for proper function.

Expand  

It saved, but unfortunately it's still not working.

Here's how I set it up:

  Reveal hidden contents

 

Edited by wilwhitt56
Link to comment
Share on other sites

Are you testing on a new game or one that has not seen the mod you are working on?  If the object that the script is attached to is already loaded and stored in the save file, not all script changes will be recognized.

Without actually seeing the setup and how everything hooks together, I cannot begin to speculate where it might be failing.  The script itself is sound.

Link to comment
Share on other sites

  On 3/23/2024 at 3:50 PM, IsharaMeradin said:

Are you testing on a new game or one that has not seen the mod you are working on?  If the object that the script is attached to is already loaded and stored in the save file, not all script changes will be recognized.

Without actually seeing the setup and how everything hooks together, I cannot begin to speculate where it might be failing.  The script itself is sound.

Expand  

I do a new game every time. I've made sure all of the properties are attached to their respected parts. The activator itself is a container with the mesh of a ledger, which has the script in it. The process itself is the object references are connected to static objects, aka chests, which are scattered around the chamber. These chests are the source for the various gold piles, jewels, shinies, etc that are in the room inself. These shinies are connected via Enable Parent to their respected chests. The chests though are set to initially disabled, making both the chest AND the loot connected to them invisible. When someone reaches the set goal for the first chest, the script triggers and makes the chest visible again, along with all connected loot.

Edited by wilwhitt56
Link to comment
Share on other sites

OnInit, in particular, will not run again when you update the script without starting a new game.

The console command "sqv EW_Treasury" should give you more info on the current state of your script variables (assuming the quest is called EW_Treasury").

Link to comment
Share on other sites

  • Recently Browsing   0 members

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