Jump to content

Delay when using a script from a constructible terminal


madmatty946

Recommended Posts

Hi,

 

I am trying to do the following:

 

* Make an object that can be built in workshop mode and that adds a menu to the workshop terminal if it is hooked up. This works.

* When the menu item is clicked on the linked terminal, loop through all workshops and check how many items of a certain type exist in all workshops.

* Display the number as a notification.

 

My script compiles but when I exectue the menu point in the terminal nothing happens. Then, after a long time (like sleeping in a bed, leaving the settlement etc) it executes. Can someone explain what's wrong?

 

Here is my script fragment:

WorkshopScript[] allWorkshops = WorkshopParent.Workshops as WorkshopScript[]
debug.notification("Starting script.")

int total = 0
int i = 0
int ccount = 0

while (i < allWorkshops.Length)
	 WorkshopScript curWS = allWorkshops[i]

	;how many items are stored here?
	ccount = curWS.GetItemCount(Item)

	;add number to the total count
	total += ccount
	i+=1
endWhile

debug.notification("Total number is " + total)
Game.GetPlayer().AddItem(Item,1)
Edited by madmatty946
Link to comment
Share on other sites

Could you maybe pinpoint where you think my code has a performance issue?

 

Because the loop goes through O(10) entries and adds up numbers, I don't see why this should take minutes to run. Also, the notification in the first line of the script shows up only after minutes so it seems like the script doesn't event start until quite a while has passed.

I honestly don't see where these 10 lines of code should have any performance issues.

Edited by madmatty946
Link to comment
Share on other sites

  • Recently Browsing   0 members

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