Display case manager script help

Banana Lord

Member
Thanks, I'll have a look at that later. The reason I used print the way I did was that I wanted the item names hard against the left edge of the window for easier scanning. Otherwise I end up with the prefix and suffix attached to every item name.
 

Bale

Minion
I can't see any reason to want to use a record in this script. Those are only used when each object has multiple values attached to it. You only need one. Hopefully this answers the rest of your questions:

PHP:
int [item] list;
void setup_display() {
	file_to_map("DC Data.txt", list);
	foreach key in $items[]
		if(display_amount(key)>0 && !(list contains key)) 
			list [key] = -1;
	map_to_file(list, "DC Data.txt");
}

Edit: Ninja'ed by That FN Ninja! Guess I took too long to write that little bit of code.

Edit2: Ah, That FN Ninja's code has a little problem in that it will change the value of items in your list to -1, even if you previously set them to other values.
 
Last edited:

Banana Lord

Member
I'm still going through them both. It would be really helpful if you could highlight differences in functionality of the two scripts, if there are any, much like you did in your second edit.

EDIT: Oh and slightly off topic, but is there a simpler way to set multiple conditions to if than if(...) if(...) if(...)?

EDIT2: His code also has a slight problem in that it tries to move my entire inventory to my DC. Actually, given my track record that could be my fault, but I haven't changed anything so maybe not.
 
Last edited:

Bale

Minion
EDIT: Oh and slightly off topic, but is there a simpler way to set multiple conditions to if than if(...) if(...) if(...)?

If you want to act on only 1 of several conditions:

PHP:
	switch {
	case list[key] == 0:
		// put them all in the display case
		break;  // This ends the case. If this isn't here, it will execute every following statement without bothering to check the case.
	case list[key] > 0:
		// put a certain amount into the display case
		break;
	case list[key] < 0:
		// put all except for a specific amount into the display case
		break;
	}

I'm not sure if that is really what you're looking for, so please be more specific if I missed your point.
 

Banana Lord

Member
Well here's an example:
Code:
if(my_inebriety() < 20) 
 if(my_adventures() < 201) 
  if(have_effect($effect[Carlweather's Cantata of Confrontation])>0) 
   if(user_confirm("Have you finished farming for today?") == true) 
    cli_execute("shrug Carlweather's Cantata of Confrontation");
Is there a better way of doing that?

EDIT: OK, well back to the matter at hand, what's the difference between void setup_display() and void main(). You used the former in the last bit of code you posted, and the former in the first. With main in place of setup_display the script functions perfectly, otherwise it does nothing.
 
Last edited:
Edit2: Ah, That FN Ninja's code has a little problem in that it will change the value of items in your list to -1, even if you previously set them to other values.

As far as I've read so far the sole purpose of the DC data.txt is to track whether an item should be displayed or not rendering the resulting int value in the map functionally useless. That is why I scripted it the way I did. I guess I should have changed it to boolean [item] dc to make that point clear. If the only thing that Banana Lord wants to do is display all of a given item the int would be useless. I left it as an int in case he wanted to change something in the future.

EDIT2: His code also has a slight problem in that it tries to move my entire inventory to my DC. Actually, given my track record that could be my fault, but I haven't changed anything so maybe not.

The code I posted only tries to put the items contained in the DC Data.txt file in your display case.
 

Banana Lord

Member
I do intend to try and have the script read the second column in the data file to find out how many of each item to display.

Really? When I run the code exactly as you posted it, it tries to shift my entire inventory to my DC.
 
Well here's an example:
Code:
if(my_inebriety() < 20) 
 if(my_adventures() < 201) 
  if(have_effect($effect[Carlweather's Cantata of Confrontation])>0) 
   if(user_confirm("Have you finished farming for today?") == true) 
    cli_execute("shrug Carlweather's Cantata of Confrontation");
Is there a better way of doing that?

Yes:

Code:
if(my_adventures() < 201 && have_effect($effect[Carlweather's Cantata of Confrontation]) > 0 && user_confirm("Have you finished farming for today?") == true)
    cli_execute("shrug Carlweather's Cantata of Confrontation");
 

Banana Lord

Member
Ah thanks!

@Bale: Would it not be very easy to add some code to OCD to have everything in "DC Data.txt" automatically added to save rather than me having to remember to manually add items when I decide to collect them?
 
Really? When I run the code exactly as you posted it, it tries to shift my entire inventory to my DC.

You are right. Sorry. :eek:

Code:
    foreach key in get_inventory()
        if(item_amount(key) > 0)
should be:
Code:
    foreach key in get_inventory()
        if(item_amount(key) > 0 && dc contains key)

Edit:
I do intend to try and have the script read the second column in the data file to find out how many of each item to display.

My code like Bale mentioned does not take into account the int.
 
Last edited:

Banana Lord

Member
Haha, don't apologise. If you've read the rest of the thread you'll know that I sent Bale and Spiny on a wild goose chase before. Just a tad embarrassing :p
 

Banana Lord

Member
Right, well here's my proposed integration with OCD:
Code:
int [item] DC;
file_to_map("DC Data.txt", DC);
foreach key in DC
    save [key] = -1;
int [item] save; is of course already in OCD.

I posted this question as an edit, but as the thread moved on to a new page shortly after that I'm not sure if it got noticed: What's the difference between void setup_display() and void main(). Bale used the former in the last bit of code you posted, and the former in the first. With main in place of setup_display the script functions perfectly, otherwise it does nothing.

EDIT: D'oh, double post.
 
EDIT: OK, well back to the matter at hand, what's the difference between void setup_display() and void main(). You used the former in the last bit of code you posted, and the former in the first. With main in place of setup_display the script functions perfectly, otherwise it does nothing.

As far as I understand it void main() and void setup_display() are functions. When you run a script anything not in a function will be executed, then anything in main will be executed. For a function like void setup_display() to be executed it must be invoked:

Code:
void setup_display(){
  //code
}

void main(){
  setup_display();
}
Right, well here's my proposed integration with OCD:
Code:
int [item] DC;
file_to_map("DC Data.txt", DC);
foreach key in DC
    save [key] = -1;

First, I assume you intend to add this to OCD Data Creator.ash?
Second, You are ignoring the int value in the DC Data.txt (This is why I was confused in the first place).

To account for the int use this instead:

Code:
int [item] DC;
 file_to_map("DC Data.txt", DC);
 foreach key, num in DC
     save [key] = num;
This seems unnecessary however. If you are already using or plan on using Bale's excellent OCD Inventory Control script I would suggest just taking the time to set it up. New content comes out at a rate that is fairly easy to keep up with.
 
Last edited:

Banana Lord

Member
OK, I *think* I understand. Let's use the script as it is currently as an example:
Code:
int [item] list;
void main() {
    file_to_map("DC Data.txt", list);
    foreach key in $items[]
        if(display_amount(key)>0 && !(list contains key)) 
            list [key] = -1;
    map_to_file(list, "DC Data.txt");

file_to_map("DC Data.txt", list);
print("Putting...");
foreach key in list
    if(item_amount(key)>0)
        print(""+key, "blue");
        print("... into display case");    
file_to_map("DC Data.txt", list);
foreach key in list
    if(item_amount(key)>0) put_display( item_amount(key), key);
    
    print("DC updated", "green");

}

Now what difference would it make if I removed void main()? And I'm still a little unclear as to why Bale used setup_display rather than main as it appears to prevent the script from functioning.
 

Bale

Minion
I only wanted to show you one self-contained function, not a whole program. Here's how the function works in context. Note how it is called from within main. BTW, you don't need to keep using file_to_map(). Once you've done it, you're good.

PHP:
int [item] list; 

void setup_display() { 
    file_to_map("DC Data.txt", list); 
    foreach key in $items[] 
        if(display_amount(key)>0 && !(list contains key))  
            list [key] = -1; 
    map_to_file(list, "DC Data.txt"); 
} 

void display_stuff() {
	print("Putting...");
	foreach key in list
		if(item_amount(key)>0)
			print(" "+key, "blue");
	print("... into display case");    
	foreach key in list
		switch {
		case list[key] == 0: 
			put_display(item_amount(key), key);
			break;
		case list[key] > 0: 
			int dis_amount = max(list[key] - display_amount(key), 0);
			if(dis_amount >0 && item_amount(key) > 0)
				put_display(min(item_amount(key), dis_amount), key);
			break; 
		case list[key] < 0: 
			if(item_amount(key) + list[key] > 0)
				put_display(item_amount(key) + list[key], key);
		break; 
		}
	print("DC updated", "green");
}

void main() {
	setup_display();
	display_stuff();
}
 
Last edited:

Banana Lord

Member
OK, I think I understand most of that. What do max, min, switch, case and break do exactly?

Also, that code doesn't work for me. It prints "Putting... ... into display case DC updated" but it doesn't update "DC Data.txt" nor does it move items into my display case. How am I supposed to handle the second column of the data file? I've tried using negative numbers, zero and positive numbers.
 

lostcalpolydude

Developer
Staff member
OK, I think I understand most of that. What do max, min, switch, case and break do exactly?

Min takes two numbers and returns the smaller value. Max works similarly.

Switch and case work like if. Switch is used to enclose a set of case statements, and each case specifies the input conditions that trigger it.
 

Bale

Minion
How am I supposed to handle the second column of the data file? I've tried using negative numbers, zero and positive numbers.
You can decide for yourself what it means, but in the example I just posted:

  • 0 : Puts all of an item into the display case.

  • positive number : Will only try to put that number in the display case (keeping any extra in inventory.)

  • negative number : Will put all into the display case except for the absolute value. Essentially, this says how many to NOT put into the display case.

-1, means put all except for 1 into display case.
5, means only display 5.​

If you don't like that, then make up your own method.
 

Banana Lord

Member
That's what I thought from your code, but as I said, when I run the script it doesn't update the data file or put items into my DC, regardless of the value of the second column.
 

Bale

Minion
I don't have time to worry about that right now, but here are a few things to check. First, verify that you don't have a file named "DC Data.txt" somewhere in /scripts. Then please try it without a "DC Data.txt" file anywhere. Let me know if it creates one in your /data directory.

If there were no useful results from those tests, then please attach your script and datafile to your post so that it can be examined by me or someone else. We might spot a strange problem that we didn't think to warn you away from.
 
Top