Post Office

I’m messing with a script for a post office and I know what I need to do, I’m just butchering the commands for setting variables. The main npc is the letter bag, which is responsible for picking up letters, creating addresses, and reporting stats. (Delivery count, wages, etc.) The mailbox npc will simply know its address, clear the address from the letter, then determine pay rate and then add that to pay. I messed up the code worse when I was impatiently trying to get it to work, but I mostly need to know how to set variables within strings and whether I’m trying to catch their them right. I sorta had it working before I made everything into setstring, but it wasn’t retaining the information when I’d go back and forth between the editor…

// NPC made by Garacat
// Delivery Bag
// December 2008

if (playertouchsme){toweapons Delivery Bag;}

if (playerchats && isweapon) {
//-----------------------------------------------------------------------------------------------------
//   Pickup determines letterbag capacity, refills the letterbag to that "capacity",
// and should only work in the post office
//-----------------------------------------------------------------------------------------------------
  if (strequals(#c,pickup) && player.letters=0 && playerlevel=postoffice.graal && !current.letter>0){
      if (deliveries<25){setstring bag.capacity,1;}
      if (deliveries>24 && deliveries<100){setstring bag.capacity,5;}
      if (deliveries>99 && deliveries<250){setstring bag.capacity,10;}
      if (deliveries>249 && deliveries<500){setstring bag.capacity,15;}
      if (deliveries>499 && deliveries<1000){setstring bag.capacity,20;}
      if (deliveries>999){setstring bag.capacity,25;}
    setstring player.letters,#v(bag.capacity);
  }

//-----------------------------------------------------------------------------------------------------
// Next delivery subtracts a "converts" a letter to an address and translates it into a name
//-----------------------------------------------------------------------------------------------------
  if (strequals(#c,next delivery) && player.letters>0 && !current.letter>0){
    setstring player.letters,player.letters-1;
    setstring current.letter,int(random(1,25));
      if (current.letter=1){setstring letter.boxname,Test House}
      if (current.letter=2){setstring letter.boxname,a}
      if (current.letter=3){setstring letter.boxname,B}
      if (current.letter=4){setstring letter.boxname,D}
      if (current.letter=5){setstring letter.boxname,E}
      if (current.letter=6){setstring letter.boxname,B}
      if (current.letter=7){setstring letter.boxname,DS}
      if (current.letter=8){setstring letter.boxname,E}
      if (current.letter=9){setstring letter.boxname,W}
      if (current.letter=10){setstring letter.boxname,E}
      if (current.letter=11){setstring letter.boxname,G}
      if (current.letter=12){setstring letter.boxname,A}
      if (current.letter=13){setstring letter.boxname,F}
      if (current.letter=14){setstring letter.boxname,E}
      if (current.letter=15){setstring letter.boxname,E}
      if (current.letter=16){setstring letter.boxname,E}
      if (current.letter=17){setstring letter.boxname,G}
      if (current.letter=18){setstring letter.boxname,E}
      if (current.letter=19){setstring letter.boxname,G}
      if (current.letter=20){setstring letter.boxname,E}
      if (current.letter=21){setstring letter.boxname,E}
      if (current.letter=22){setstring letter.boxname,A}
      if (current.letter=23){setstring letter.boxname,E}
      if (current.letter=24){setstring letter.boxname,W}
      if (current.letter=25){setstring letter.boxname,Q}
      setplayerprop #c,#s(letter.boxname);
  }

//----------------------------------------------------------------------------------------------------
//Following simply allows player to check stats
//Total deliveries
// Accumulative Pay (Determined mailbox npc, pay can be collected at post office from npc)
// Next delivery (When address is already set)
// Wage (Also determined by mailbox npc)
//----------------------------------------------------------------------------------------------------
  if (strequals(#c,delieveries)){setplayerprop #c,#v(deliveries)}
  if (strequals(#c,pay)){setplayerprop #c,#v(postal.pay)}
  if (strequals(#c,next delivery && player.letters>0 && current.letter>0)){setplayerprop #c,#s(letter.boxname)}
  if (strequals(#c,wage)){setplayerprop #c,#v(player.wage)}
}
//---------------------------------------------------------------------------------------------------
// End

To set a variable within a string:
setstring string,#v(variable);

To turn a string into a variable:
variable = strtofloat(#s(string));

To add onto a string (as a variable) into a string:
setstring string,#v(strtofloat(#s(string)) + variable);

[hr][/hr]

Also noticing a huge redundancy with your setstrings.

setstring current.letter,int(random(1,25));
this.E = {5,8,10,14,15,16,18,20,21,23};
if(strtofloat(#s(current.letter)) in this.E) setstring letter.boxname,E;

And:
if (current.letter=25){setstring letter.boxname,Q}

25 would never be reached with a int(random(1,25)).
Eg: lowest would be 1.0001 and highest would be 24.9999. int(1.0001) = 1, int(24.9999) = 24

Did you fail to mention that all the ='s should be =='s in the if’s, or is that different in GS1…?

Messed around with the script some more, added to the random to make up for the rounding down and named all of the houses. Still messing around trying to make the strings work, I’m sure I’m doing something stupid. Not sure whether pickup’s working, but I know next delivery isn’t.

Gah, didn’t see the thing on =='s until afterwords for some reason, I’ll have to try it later…

// Delivery Bag
// December 2008

if (playertouchsme){toweapons Delivery Bag;}

if (playerchats && isweapon) {
//-----------------------------------------------------------------------------------------------------
// Pickup determines letterbag capacity, refills the letterbag to that "capacity",
// and should only work in the post office
//-----------------------------------------------------------------------------------------------------
  if (playerchats && strequals(#c,pickup) && strequals(player.letters,#v(0)) && playerlevel=postoffice.graal && !strequals(current.letter,0)){
      if (deliveries<25){setstring bag.capacity,1; setplayerprop #c,Got 1 Letter;}
      if (deliveries>24 && deliveries<100){setstring bag.capacity,5; setplayerprop #c,Got 2 Letters;}
      if (deliveries>99 && deliveries<250){setstring bag.capacity,10; setplayerprop #c,Got 3 Letters;}
      if (deliveries>249 && deliveries<500){setstring bag.capacity,15; setplayerprop #c,Got 4 Letters;}
      if (deliveries>499 && deliveries<1000){setstring bag.capacity,20; setplayerprop #c,Got 5 Letters;}
      if (deliveries>999){setstring bag.capacity,25;}
    setstring player.letters,#v(strtofloat(#s(bag.capacity)));
  }

//-----------------------------------------------------------------------------------------------------
// Next delivery subtracts a "converts" a letter to an address and translates it into a name
//-----------------------------------------------------------------------------------------------------
  if (playerchats && strequals(#c,next delivery) && strtofloat(#s(player.letters)!=0) && strtofloat(#s(current.letter)=0)){
    setstring player.letters,#v(strtofloat(player.letters)) +-1;
    setstring current.letter,int(random(1,21));
      if (strtofloat(#s(current.letter)=1)){setstring letter.boxname,Garacat's House;}
      if (strtofloat(#s(current.letter)=2)){setstring letter.boxname,Lufia's House;}
      if (strtofloat(#s(current.letter)=3)){setstring letter.boxname,Ninja's House;}
      if (strtofloat(#s(current.letter)=4)){setstring letter.boxname,Blue's House;}
      if (strtofloat(#s(current.letter)=5)){setstring letter.boxname,Brown's House;}
      if (strtofloat(#s(current.letter)=6)){setstring letter.boxname,Red's House;}
      if (strtofloat(#s(current.letter)=7)){setstring letter.boxname,Cyan's House;}
      if (strtofloat(#s(current.letter)=8)){setstring letter.boxname,Sally's House;}
      if (strtofloat(#s(current.letter)=9)){setstring letter.boxname,Jack's House;}
      if (strtofloat(#s(current.letter)=10)){setstring letter.boxname,Chiron's House;}
      if (strtofloat(#s(current.letter)=11)){setstring letter.boxname,Arkantos's House;}
      if (strtofloat(#s(current.letter)=12)){setstring letter.boxname,Magi's House;}
      if (strtofloat(#s(current.letter)=13)){setstring letter.boxname,Jillian's House;}
      if (strtofloat(#s(current.letter)=14)){setstring letter.boxname,Bart's Treehouse;}
      if (strtofloat(#s(current.letter)=15)){setstring letter.boxname,Tim's House;}
      if (strtofloat(#s(current.letter)=16)){setstring letter.boxname,Pamala's House;}
      if (strtofloat(#s(current.letter)=17)){setstring letter.boxname,Swindleson Manor;}
      if (strtofloat(#s(current.letter)=18)){setstring letter.boxname,Merc's Place;}
      if (strtofloat(#s(current.letter)=19)){setstring letter.boxname,Chev's House;}
      if (strtofloat(#s(current.letter)=20)){setstring letter.boxname,Madi's House;}
      setplayerprop #c,#s(letter.boxname);
  }

//----------------------------------------------------------------------------------------------------
// Following simply allows player to check stats
// Total deliveries
// Accumulative Pay (Determined mailbox npc, pay can be collected at post office from npc)
// Next delivery (When address is already set)
// Wage (Also determined by mailbox npc)
//----------------------------------------------------------------------------------------------------
  if (strequals(#c,delieveries)){setplayerprop #c,#s(deliveries)}
  if (strequals(#c,pay)){setplayerprop #c,#s(postal.pay)}
  if (strequals(#c,next delivery && player.letters>0 && current.letter>0)){setplayerprop #c,#s(letter.boxname)}
  if (strequals(#c,wage)){setplayerprop #c,#s(player.wage)}
  if (strequals(#c,letters)){setplayerprop #c,#s(player.letters)}
}

//----------------------------------------------------------------------------------------------------
//END
//----------------------------------------------------------------------------------------------------

Oh snap, you caught me. Lol

Yes, they’re supposed to be ‘==’ for comparisons. Graal adds some flexibility by allowing ‘=’ for comparisons but its bad coding.

Also:
setstring player.letters,#v(strtofloat(player.letters)) ±1;

Nein. That would give you “<“player.letters” to variable> ±1”
setstring player.letters,#v(strtofloat(#s(player.letters)) -1);

Just remember, we’re not “tearing your script apart”, we’re helping. lol
Also, thanks Nalin, I didn’t bother looking that deep into it so that didn’t catch my eye, lol.

Thanks guys, I finally managed to get it working with all your advice. There might be one bug with it yet, but everything else seems to be working perfect and I was able to convert the mailbox npc and pay npc over from variables to strings in no time at all once I knew what I was doing. The one bug I noticed is that I have to pick up the letterbag weapon every time I restarted from the editor in order to use pickup, but it seems to be a minor bug so I’ll mess with it later.

// NPC made by Garacat
// Delivery Bag
// December 2008

if (playertouchsme){toweapons Delivery Bag;}

if (playerchats && isweapon) {
//-----------------------------------------------------------------------------------------------------
// Pickup determines letterbag capacity, refills the letterbag to that "capacity",
// and should only work in the post office
//-----------------------------------------------------------------------------------------------------
  if (playerchats && strequals(#c,pickup) && strtofloat(#s(player.letters))==0 && strequals(#L,postoffice.graal) && strtofloat(#s(current.letter))==0){
      if (strtofloat(#s(deliveries))<25){setstring bag.capacity,1; setplayerprop #c,Got 1 Letter;}
      if (strtofloat(#s(deliveries))>24 && strtofloat(#s(deliveries))<100){setstring bag.capacity,5; setplayerprop #c,Got 2 Letters;}
      if (strtofloat(#s(deliveries))>99 && strtofloat(#s(deliveries))<250){setstring bag.capacity,10; setplayerprop #c,Got 3 Letters;}
      if (strtofloat(#s(deliveries))>249 && strtofloat(#s(deliveries))<500){setstring bag.capacity,15; setplayerprop #c,Got 4 Letters;}
      if (strtofloat(#s(deliveries))>499 && strtofloat(#s(deliveries))<1000){setstring bag.capacity,20; setplayerprop #c,Got 5 Letters;}
      if (strtofloat(#s(deliveries))>999){setstring bag.capacity,25;}
    setstring player.letters,#v(strtofloat(#s(bag.capacity)));
  }

//-----------------------------------------------------------------------------------------------------
// Next delivery subtracts a "converts" a letter to an address and translates it into a name
//-----------------------------------------------------------------------------------------------------
  if (playerchats && strequals(#c,next delivery) && strtofloat(#s(player.letters))!=0 && strtofloat(#s(current.letter))==0){
    setstring player.letters,#v(strtofloat(#s(player.letters))-1);
    po.cl=int(random(1,21));
    setstring current.letter,#v(po.cl);
      if (strtofloat(#s(current.letter))==1){setstring letter.boxname,Garacat's House;}
      if (strtofloat(#s(current.letter))==2){setstring letter.boxname,Lufia's House;}
      if (strtofloat(#s(current.letter))==3){setstring letter.boxname,Ninja's House;}
      if (strtofloat(#s(current.letter))==4){setstring letter.boxname,Blue's House;}
      if (strtofloat(#s(current.letter))==5){setstring letter.boxname,Brown's House;}
      if (strtofloat(#s(current.letter))==6){setstring letter.boxname,Red's House;}
      if (strtofloat(#s(current.letter))==7){setstring letter.boxname,Cyan's House;}
      if (strtofloat(#s(current.letter))==8){setstring letter.boxname,Sally's House;}
      if (strtofloat(#s(current.letter))==9){setstring letter.boxname,Jack's House;}
      if (strtofloat(#s(current.letter))==10){setstring letter.boxname,Chiron's House;}
      if (strtofloat(#s(current.letter))==11){setstring letter.boxname,Arkantos's House;}
      if (strtofloat(#s(current.letter))==12){setstring letter.boxname,Magi's House;}
      if (strtofloat(#s(current.letter))==13){setstring letter.boxname,Jillian's House;}
      if (strtofloat(#s(current.letter))==14){setstring letter.boxname,Bart's Treehouse;}
      if (strtofloat(#s(current.letter))==15){setstring letter.boxname,Tim's House;}
      if (strtofloat(#s(current.letter))==16){setstring letter.boxname,Pamala's House;}
      if (strtofloat(#s(current.letter))==17){setstring letter.boxname,Swindleson Manor;}
      if (strtofloat(#s(current.letter))==18){setstring letter.boxname,Merc's Place;}
      if (strtofloat(#s(current.letter))==19){setstring letter.boxname,Chev's House;}
      if (strtofloat(#s(current.letter))==20){setstring letter.boxname,Madi's House;}
      setplayerprop #c,#s(letter.boxname);
  }

//----------------------------------------------------------------------------------------------------
// Following simply allows player to check stats
// Total deliveries
// Accumulative Pay (Determined mailbox npc, pay can be collected at post office from npc)
// Next delivery (When address is already set)
// Wage (Also determined by mailbox npc)
//----------------------------------------------------------------------------------------------------
  if (strequals(#c,delieveries)){setplayerprop #c,#s(deliveries)}
  if (strequals(#c,pay)){setplayerprop #c,#s(postal.pay)}
  if (playerchats && strequals(#c,next delivery) && strtofloat(#s(current.letter))!=0){setplayerprop #c,#s(letter.boxname)}
  if (strequals(#c,wage)){setplayerprop #c,#s(player.wage)}
  if (strequals(#c,letters)){setplayerprop #c,#s(player.letters)}
}

//----------------------------------------------------------------------------------------------------
//END
//----------------------------------------------------------------------------------------------------

Another method for shortening code.
Instead of all of the:
if (strtofloat(#s(current.letter))==20){setstring letter.boxname,Madi’s House;}

You could have
tokenize Garacat’s House,Madi’s House,Chev’s House,Merc’s Place,etc;
this.i = int(random(0,21));
setstring letter.boxname,#t(this.i);

If they were all “houses” and not the occasional ‘Place’ or ‘Manor’ Could short it even further with:
tokenize Garacat,Madi,Chev,Merc,etc;
this.i = int(random(0,21));
setstring letter.boxname,#t(this.i)'s House;

I just wasted my time looking through it, and theres allready like nine responses. Attention Hogging!

P.s. I hope your post office works like Paper boy for nes, where I can bike around throwing papers at dogs, dodging life ending danger.

Aren’t tokens evil? Last I knew they were kinda bad to use.

I think you’re thinking of strings. Too many strings is bad :stuck_out_tongue:

Gah, Stefan left me a note not to make a post office using strings…

“You can’t use these string variables for making post offices, but you can use it to save special player properties (the level where an item was collected, the colors of his coat before he was thrown into prison etc.).”
-2000 by Stefan Knorr

O.o Why would you ask Stefan?