Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Insomniac
Wanderer


Joined: 25 Mar 2004
Posts: 78
Location: United Kingdom

PostPosted: Sat Apr 17, 2004 12:50 pm   

Question about looping
 
Greetings.

I have a trigger setup that captures all the treasure dropped when I kill a mob and stores it a stringlist variable named @ItemsToGet.

I then loop through it using #FORALL to get each item and put it in my container and then delete the item from @ItemsToGet.

This works fine, until the container is full, at which point I'd like to set a different container and STILL put the item that wouldn't fit AND the rest of the items contained in the @ItemsToGet variable away too.

My attempts at trying this has failed thus far, it all goes pear shaped when the container is full.

This is what I have so far....

#TRIGGER {You find (*) (%w).} {;#VAR CurrentItem "%2";#ADDITEM ItemsToGet @CurrentItem}

#TRIGGER {^The corpse of a} {#FORALL @ItemsToGet {#IF (%ismember({%i}, @ItemIgnoreList)) {ItemsToGet = %delitem("%i",@ItemsToGet)}};#WHILE (@ItemsToGet <> "") {#VAR GetItem %item(@ItemsToGet, 1);get @GetItem;put @GetItem in @Container;ItemsToGet = %delitem(@GetItem,@ItemsToGet)}}

#TRIGGER {It won't fit} {#VAR Container "sack";put @GetItem in @Container}

And a sample output when it works well (Container not full) Sent input is bold.

search kobold
You find a rusty scimitar.
You find a kobold hide.
The corpse of a kobold decays.
get hide
put hide in backpack
get scimitar
put scimitar in backpack
You get a kobold hide.
You put a kobold hide in a backpack.
You get a rusty scimitar.
You put a rusty scimitar in a backpack.

And when the container is full...

search kobold
You find a rusty broadsword.
You find a kobold hide.
The corpse of a kobold decays.
get hide
put hide in backpack
get broadsword
put broadsword in backpack
You get a kobold hide.
It won't fit.
put broadsword in sack
You don't have a hand free to get that.
You cannot find it.
You are not holding that.

I think it just needs to be setup so that it grabs one Item at a time and checks that it's been put away, instead of grabbing all/putting all away.

Any help please?

-=Insomniac=-
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Apr 17, 2004 3:30 pm   
 
quote:
I think it just needs to be setup so that it grabs one Item at a time and checks that it's been put away, instead of grabbing all/putting all away.


Sounds like a good plan.
#TR {You find * (%w).} {#IF !(%ismember( %1, @ItemIgnoreList)) {#VAR ItemsToGet %additem( %1, @ItemsToGet)}}
#TR {^The corpse of a} {#IF (%numitems( @ItemsToGet) > 0) {get %item( @ItemsToGet, 1);put %item( @ItemsToGet, 1) in @Container}}
#TR {^You put } {#DELN ItemsToGet 1;#IF (%numitems( @ItemsToGet) > 0) {get %item( @ItemsToGet, 1);put %item( @ItemsToGet, 1) in @Container}}
#TR {It won't fit} {#IF (@Container <> "sack") {#VAR Container sack;put %item( @ItemsToGet, 1) in @Container} {#SAY Full}}
Reply with quote
Insomniac
Wanderer


Joined: 25 Mar 2004
Posts: 78
Location: United Kingdom

PostPosted: Sat Apr 17, 2004 7:16 pm   
 
Worked brilliantly!

You're too good LightBulb, I really appreciate it.

Will pick it apart and try and learn from it now

-=Insomniac=-
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net