Jump to content

Getting a list of all workshops


Recommended Posts

Excellent. Messed around and given up without making a quest and setting it up noting the 'Stores Text' bit.

 

I have more set up to do, but thank you so much, I'm very encouraged you've got this working (both the message text replacement and the settlement list).

Link to comment
Share on other sites

Okay, I've tried but I really don't understand this loop, from CleanSettlementScriptWorks:

int index = 0
bool break = false
while (index < GetWorkshops().length)
  if !break
    if ShouldCleanSettlement(Workshops[index])
      QueueSettlement(Workshops[index])
      break = true
    endif
    index += 1
  else 
    index = GetWorkshops().length
  endif
endWhile

To my eyes, it would go (assuming a populated Workshops array):
index is 0
break is false
0 is less than the length of the Workshops array, so
break is false, so
Test the workshop at [index] in Workshops, and if it returns true then
Queue that workshop for cleaning
Set break to true
incremement index by 1
Back to While: index is still less than Workshops length, so
break is true, so
set index to be equal to Workshops length
Back to the While: index is no longer less than Workshops, so
We're done.

I don't see how this loops, instead of just exiting after the first one?

Link to comment
Share on other sites

@spacefiddel:

 

I might be mistaken here, but I think the point is to exit the while once a settlement has been passed to the QueueSettlement() function ... if you go to the ShouldCleanSettlement() you will notice there is a check there to see if that settlement has been cleaned so it does not get cleaned twice. Basically, it will exit after the first one, if the first one meets the criteria... but the next time the script runs the first one will return false for the ShouldCleanSettlement(), the loop will continue.

Link to comment
Share on other sites

@spacefiddel:

 

I might be mistaken here, but I think the point is to exit the while once a settlement has been passed to the QueueSettlement() function ... if you go to the ShouldCleanSettlement() you will notice there is a check there to see if that settlement has been cleaned so it does not get cleaned twice. Basically, it will exit after the first one, if the first one meets the criteria... but the next time the script runs the first one will return false for the ShouldCleanSettlement(), the loop will continue.

 

Makes sense, but index is reset to 0 every time we get back here - so how is it checking anything other than Array[0]?

Link to comment
Share on other sites

@spacefiddel:

 

The index is set back 0 before you enter the loop... once you are in the WHILE loop the index keeps increasing until it exits. Basically it keeps increasing if the settlements are clean or don't meet the 10 settler criteria. Setting index = 0 is done to initialize the index variable BEFORE you enter the loop, once you are inside the while loop you never repeat the index = 0 within the same function call. Let me know if its not clear yet.

Link to comment
Share on other sites

@spacefiddel:

 

The index is set back 0 before you enter the loop... once you are in the WHILE loop the index keeps increasing until it exits. Basically it keeps increasing if the settlements are clean or don't meet the 10 settler criteria. Setting index = 0 is done to initialize the index variable BEFORE you enter the loop, once you are inside the while loop you never repeat the index = 0 within the same function call. Let me know if its not clear yet.

 

No, I think you're not seeing what I'm saying -

 

It's set to 0 before you enter the loop, yes; it has to be. So, during *this call* of the function the loop is in, it increases until it finds the *first settlement* to clean - then it exits.

 

The next time the function is called, it again resets the index to 0 before the while loop. So it will, again, go up the same list of elements, and reach the same result. See what I mean? So: is there something that makes this array "not the same every time we look at it?"

Link to comment
Share on other sites

 

No, I think you're not seeing what I'm saying -

 

It's set to 0 before you enter the loop, yes; it has to be. So, during *this call* of the function the loop is in, it increases until it finds the *first settlement* to clean - then it exits.

 

The next time the function is called, it again resets the index to 0 before the while loop. So it will, again, go up the same list of elements, and reach the same result. See what I mean? So: is there something that makes this array "not the same every time we look at it?"

 

 

The Workshops array is indeed the same every time we look at it, but the loop in CheckForSettlementsToClean() doesn't reach the same result every time it's called by OnTimerGameTime(). Say, for example, that Workshops[0] is passed to QueueSettlement() the first time that CheckForSettlementsToClean() is called. The next time that CheckForSettlementsToClean() runs, ShouldCleanSettlement(Workshops[0]) will return false, and the loop will then look at Workshops[1], and so on and so forth until it finds the next eligible settlement.

 

I think I may get what you're asking: why bother looping through the same Workshops array elements if they're already marked "clean" (stored in the CleanedSettlements array)? At the moment, rather than removing cleaned settlements from the Workshops array, I'm just adding them to the CleanedSettlements array and checking that array for each settlement during the loop in CheckForSettlementsToClean(). If I wanted to instead remove cleaned settlements from the Workshops array, I would just update the RecordQueuedSettlement() and SettlementIsClean() functions accordingly, and not bother with the CleanedSettlements array at all. I'm not sure whether it's more efficient to declare two arrays with a given number of elements at the beginning, or to remove elements from an existing array (resizing that array) every time CheckForSettlementsToClean() is called. Normally I think that it's considered more memory-intensive to resize an array.

Edited by comradezero
Link to comment
Share on other sites

Ahh gotcha. Okay, OOP is new to me and I wasn't considering the function in the context of what calls it, and what on. I knew you said it was working, so there had to be *something* I didn't get, but wasn't sure what.

 

I noticed you also keep the ID of the workshop in its "original place," that is, if it's element 5 in the Workshops array then it will also be [5] in the Cleaned array. For what I'm doing, I need to be able to count the length of the array to get its non-null entries, so I'm using a dynamic array.

 

As for the Workshops script vs. "Cleaned" at all - I think it's safest to leave the Workshops array as the comprehensive list of all workshops in the game and not edit it further, only referencing it. Like the recent DLC, if anything adds workshops to the game (whether Bethesda or a mod), the next time SetWorkshops is called, you'll get them all. Having one "this is definitely all the workshops the game sees right now" list pulled in seems valuable, while doing your tracking in another.

 

True story - while working on my own mod, Vault-Tec downloaded and installed between test runs. I had NO IDEA wtf I did to set off some random quest about a radio beacon until I realized the DLC had just released.

Link to comment
Share on other sites

Hi,

 

Im trying to adapt parts of your code for my own mod... this particular function is to tell if a workshop has a provisioner or not... but I cant seem to get it to work.. the variable caravans is always 0 ...

int function GetCaravanCount(WorkshopScript inputSettlement)
	int caravans = 0
	WorkshopDataScript:WorkshopRatingKeyword[] ratings
	WorkshopScript workshopRef = inputSettlement as WorkshopScript
	if (workshopRef)
		WorkshopParentScript theParent = workshopRef.WorkshopParent as WorkshopParentScript
		if (theParent)
			ratings = theParent.WorkshopRatings
			caravans = workshopRef.GetValue(ratings[theParent.WorkshopRatingCaravan].resourceValue) as int
		endif
	endif
	ratings = NONE
	return caravans
endFunction
Link to comment
Share on other sites

  • Recently Browsing   0 members

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