dst Posted August 25, 2010 Report Posted August 25, 2010 (edited) Ok...after playing all day with some scripts I realize that I can't get what I want. Maybe someone can help. So..what i want: Let's say I have 10 click-ables. I need to store for 9 of them the player name and a number so when I click the 10th I am able to see all the numbers a player has gathered. I know that I need to store an array but question is: HOW? Right now my brain is stuck and it seems I cannot find the strength to star over. Edited August 25, 2010 by dst Quote
Grido Posted August 25, 2010 Report Posted August 25, 2010 (edited) simple solution would be to have 9 seperate varibales to store on, but it's not very pretty when it comes to echoing you could also use keys if you wanted i figure, if it's just a numbers thing then give them the key ....key_9 and then set up on the 10th clicky [code]if(mds_has_rpcq_keys('key_9')){ echo "has key 9"; }[/code] Edited August 25, 2010 by Grido Quote
dst Posted August 25, 2010 Author Report Posted August 25, 2010 (edited) I though about that but my goal in the end is to sum up those numbers for each player. I would have too many "if" statements. Cause I don't expect all players to have the same numbers. Each of the numbers represents the value of a key. The more keys the better...or not. Edited August 25, 2010 by dst Quote
Burns Posted August 25, 2010 Report Posted August 25, 2010 you're lucky, i still have the pieces i wrote for apricot's quest^^ [php] @vs=mds_storage('apricotacounter', 'totu'); @vt=mds_storage('apricotacountall', 'toau'); //you'd need to set it aoau and give the stores different names or numbers @va=@storage[@vs]; //set storeages @temp= array ('name' => @uv('name'), 'lenght' => @va); @storage[@vt][@uv('id')] = @temp;} //set up and store arrays for each user [/php] Set that up in all of the 9 clickies, and have the 10th running following: [php] @va=mds_storage('apricotacountall', 'toau'); @vb=mds_storage('apricotacountall1', 'toau'); @vc=mds_storage('apricotacountall2', 'toau');//_load all stores and so on... if (@uv('id')==53832){ //use your own id there foreach(@storage[@va] as @vl) echo "".@vl['name']. " needed ". @vl['lenght']. "<br>";} //echo all the names and numbers of all stores used if (@uv('id')==53832){ foreach(@storage[@vb] as @vl) echo "".@vl['name']. " needed ". @vl['lenght']. "<br>";} if (@uv('id')==53832){ foreach(@storage[@vc] as @vl) echo "".@vl['name']. " needed ". @vl['lenght']. "<br>";} and so on... [/php] Quote
Kafuuka Posted August 25, 2010 Report Posted August 25, 2010 This seems the best way to store the data to me: [code]@vs = mds_storage("numbers","aoau"); // get the name of the storage if(@storage[@vs] == null)@storage[@vs] = array(); // initialize storage array if doesn't exist yet if (user does not exist in array yet) { // use a key for this @temp = array( 'name' => uv('name'), 'number1' => null, 'number2' => null, etc 'number9' => null); @storage[@vs][uv('id')] = @temp; }[/code] Checking if someone has nine numbers is a rather long condition - if !(number1 == null or number2 == null etc) - yet the alternative of keeping a counter for this seems less efficient to me. Retrieving an individual number or the sum is straightforward. The only confusing thing is that this structure is a fixed length array embedded into a variable map type yet in MD script everything is named array. Quote
Root Admin Chewett Posted August 25, 2010 Root Admin Report Posted August 25, 2010 I would merely suggest another array is used to store the numbers on each clickable. So the structure would be [player ID] > Array( 'name', Array(clicky numbers) 'time started?/anything else") then a total can be worked out by using a for loop. and by changing the range of the for loop, it would increase. decrease the amount of clickies. Where you would only need to add the data to the clickies, and the viewing script would just need a var changed Quote
awiiya Posted August 25, 2010 Report Posted August 25, 2010 (edited) I like Chewett's solution, personally, as it's easiest to add numbers to. For printing purposes, you might want to use the php function implode. It's more simple than a for loop. [code] echo implode(" ,", array(clicky numbers)); [/code] Awi Edited August 25, 2010 by awiiya Quote
dst Posted August 25, 2010 Author Report Posted August 25, 2010 At a first glance I think Burns got the closest to my needs. I don't think I explained too well: I basically need a matrix. I said 10 clickies just as an example but I might need a lot more. And I might need a lot more lines not only player name and value. I think I know how to do it using C but my problem is with the language MD script is using. There are certain things that escape me... Hope I will have time tomorrow and try to apply Burn's solution. Anyway, thank you. You all gave me ideas that I will try and maybe I will find what I need Quote
Laphers Posted August 25, 2010 Report Posted August 25, 2010 [quote name='Burns' timestamp='1282750084' post='67030'] you're lucky, i still have the pieces i wrote for apricot's quest^^ [php] @temp= array ('name' => @uv('name'), 'lenght' => @va); @storage[@vt][@uv('id')] = @temp;} //set up and store arrays for each user [/php] [/quote] Burns, is there a reason that you have preceded the function call uv() with @? I would think that would give an error unless it is a feature that I have not read about anywhere. Quote
Burns Posted August 26, 2010 Report Posted August 26, 2010 I'm willing to bet drachorns on that script, it has been running properly in MD for months now Quote
Root Admin Chewett Posted August 26, 2010 Root Admin Report Posted August 26, 2010 [quote name='Burns' timestamp='1282793883' post='67060'] I'm willing to bet drachorns on that script, it has been running properly in MD for months now [/quote] it works, but it shouldnt work. Considering all variables are preceeded by @ and that is a function. Seems like luck or random name made it work for you. Quote
Fyrd Argentus Posted August 26, 2010 Report Posted August 26, 2010 even with the word "length" mis-spelled? But I don't have a drach to bet, so nvm. Quote
Root Admin Chewett Posted August 26, 2010 Root Admin Report Posted August 26, 2010 Its a good job you dont have a drac to bet. If you actually look at his code, thats only the name of the index you are entering the variable into. as long as its mis-spelt throughout the entire program then it will still work. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.