TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

updating arrays

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
dorian



Joined: 29 Jul 2012
Posts: 66

PostPosted: Wed Sep 30, 2015 8:12 am    Post subject: updating arrays Reply with quote

Hello, i stuck with array updating, i have a big array like
array = [
321=>[foo => bar, test=>123 ,something=>321 ],
4847=>[foo=>bar, test=>213, something=>315, somethingelse=>false],
447=>[foo=>bar, test=>2173, something=>3125, somethingelse=>true],
6920=>[foo=>bar, test=>2373, something=>3125, somethingelse=>true],
]

and on event i got only this array update like so:

array = [
321=>[foo => bar, test=>122 , somethingelse=>cool]
]

how to update old array with new vlues with no missing others ones?
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Wed Sep 30, 2015 3:53 pm    Post subject: Reply with quote

How do you use that ? It seems so ugly Big Smile

Why not using #lists ? With the SET command you can simply substitute the content of the wanted item
Back to top
View user's profile Send private message
dorian



Joined: 29 Jul 2012
Posts: 66

PostPosted: Thu Oct 01, 2015 2:09 am    Post subject: Reply with quote

I recive that array in %0 in gmcp event.

i could use set but it replaces key with all values, but sometimes it contains onlyvalue that has changed eg.

Old
array = [
'123123' =>[mana=>5, hp=>10, description =troll, target=>true],
'6436' =>[mana=>0, hp=>24, description = dwarf, target=>true],
'151' =>[mana=>5, hp=>4, description = elf1, target=>true],
'342' =>[mana=>5, hp=>4, description = wlf2, target=>true]
]

Updated
array = [
'6436' =>[hp=>20]
]
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Thu Oct 01, 2015 3:40 pm    Post subject: Reply with quote

I never deal with gmcp, and the muds I use doesn't have it, but as far as I saw in this forum, no one uses the raw line from it, but instead variables are used to contain its values...

I can suggest to use an array that tt can manage better:
Code:

#nop here is defined an array with the same values as your example

#var array[123123][mana] 5
#var array[123123][hp] 10
#var array[123123][description] troll
#var array[123123][target] true
#var array[6436][mana] 0
#var array[6436][hp] 24
#var array[6436][description] dwarf
#var array[6436][target] true
#var array[151][mana] 5
#var array[151][hp] 4
#var array[151][description] elf1
#var array[151][target] true
#var array[342][mana] 5
#var array[342][hp] 4
#var array[342][description] wlf2
#var array[342][target] true

#nop and you can access every value of it, like this

#echo $array[151][hp]
4

#nop you can modify directly every value

#var array[151][hp] 110
#OK. VARIABLE {array[151][hp]} HAS BEEN SET TO {110}.

#nop you can also delete an entire element of the array, leaving the rest untouched

#unvar array[151]
#OK. {array[151]} IS NO LONGER A VARIABLE.
#var
######## VARIABLES ########
#VARIABLE {array}={{342}{{description}{wlf2}{hp}{4}{mana}{5}{target}{true}}{6436}{{description}{dwarf}{hp}{24}{mana}{0}{target}{true}}{123123}{{description}{troll}{hp}{10}{mana}{5}{target}{true}}}


The only thing you have to do is to trap the gmcp values and put them in the right way
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Tue Aug 23, 2016 9:41 pm    Post subject: Reply with quote

You can update arrays as following:

#var {array} {{x}{1}{y}{2}}
#var {array} {$array} {{z}{3}}

Should work with gmpc as well. Hope that makes sense.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group