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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Scarn
Apprentice


Joined: 24 Jul 2005
Posts: 137

PostPosted: Tue Jul 29, 2014 3:22 pm   

Editing data within a buried string.
 
I want to edit data that is within one of my strings. For reasons that will be hard to put into words, to access it I need to go through another string.

Here is my situation:

Code:
var "Equipment" =                                     A finely-shaped pearl carapace|A black set of leather and ring mail leggings
var "A finely shaped pearl carapace" =                A finely-shaped pearl carapace|1700|300|carapace|1677.49699157641
var "A black set of leather and ring mail leggings" = A black set of leather and ring mail leggings|1000|200|leggings|983.754512635379


I can pull out all the information I need, for example if I wanted to access the "leggings" from the "A black set of leather and ring mail leggings" variable I can see it like this:

Code:
#SHOW @{@Equipment.2}.4


Or if I wanted to access the "1700" from the "A finely-shaped pearl carapace" variable:

Code:
#SHOW @{@Equipment.1}.2


I've tried following this format to change things, eg to turn 1700 to 1500:

Code:
#VAR {@Equipment.1}.2 1500


However I get an error that there are too many parenthesis, I cannot used the #DELNITEM and the #ADDITEM function, as the order of the rest of the string needs to stay as it is.

Any suggestions?

Thanks in advance,
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Wed Jul 30, 2014 4:05 am   
 
Is there a reason you're not using database variables? It seems like a data structure that looks something like this would be much easier to work with:
Code:
{"A finely-shaped pearl carapace" = "1700|300|carapace|1677.49699157641" | "A black set of leather and ring mail leggings" = "1000|200|leggings|983.754512635379"}


Then, using your examples, you could do something like this to access things:
Code:
#SHOW %item( %db( @Equipment, "A black set of leather and ring mail leggings"), 3)
#SHOW %item( %db( @Equipment, "A finely-shaped pearl carapace"), 1)


To change things, you could easily pull out a single item from the equipment variable into a local variable, set items to whatever you want, and push them back:
Code:
$carapace = %db( @Equipment, "A finely-shaped pearl carapace")
$carapace = %replaceitem( 1500, 1, $carapace)
#ADDKEY Equipment "A finely-shaped pearl carapace" $carapace
Reply with quote
Scarn
Apprentice


Joined: 24 Jul 2005
Posts: 137

PostPosted: Wed Jul 30, 2014 8:26 am   
 
Again that would only add the value to the end of the string, I need to change something within it. Eg, change @Equipment.3 without effecting the other 4.
Reply with quote
Scarn
Apprentice


Joined: 24 Jul 2005
Posts: 137

PostPosted: Wed Jul 30, 2014 8:35 am   
 
Ah actually it wouldn't, the reason I prefer not to use database variables is because I have an already pretty complex system in place that gets information from triggers sets up a whole chain of other events. This would mean reformatting how the whole script works, one day, but not today! :) I just want to get away from using DELITEM and ADDITEM, as it means I cannot add further information to my existing strings.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Thu Jul 31, 2014 4:07 am   
 
You might be able to do something like @{@Equipment.1} = "blah" but I'm not sure. You might be stuck building the command as a string and executing it, something like #execute %concat( "#var """, @{@Equipment.1}, """ {blah}"). (Another thing, your variable names probably shouldn't have spaces in them, I'm sure that's not helping matters either).
Reply with quote
Scarn
Apprentice


Joined: 24 Jul 2005
Posts: 137

PostPosted: Fri Aug 01, 2014 3:14 pm   
 
I mitigate the problems of spaces in my variables by using { }. The reason they have spaces is because I trigger mud output with %1 and that loads straight into the variable, makes life a lot easier. I'll look into concat, not used that function before. For now I just use DELNITEM and ADDITEM, but as previously stated, it isn't ideal.
Reply with quote
Scarn
Apprentice


Joined: 24 Jul 2005
Posts: 137

PostPosted: Fri Aug 01, 2014 3:17 pm   
 
Just testing using the = way of adding variables, doesn't like it.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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