cutler121 Posted November 5, 2009 Report Posted November 5, 2009 I noticed that variables which are loaded and stored using retrieve(@vs)and store(@vs)are local to the user who runs the script. I am looking for a variable that will store information which every user who runs the script will get the same value. This variable could be used to store the number of times a script is called or store the name of the last person running the script so it could be displayed for the next user. Is there any kind of variable which can do this? Cutler Quote
Rendril Posted November 5, 2009 Report Posted November 5, 2009 (edited) I found out yesterday that the storages have their functionality done. Tested with aoau and aotu. Here is how to use it [code] //give @vs the storage's ID @vs = mds_storage("storage_name", "storage_type"); //to save @storage[@vs] = array("data", "that", "I", "am", "storing"); //to load @va = @storage[@vs]; [/code] You do not need to call any save routines, the MD Script will do it for you. The descriptions in the manual are obsolete and need to be changed, but you can refer to them for the storage types avaiable. Edited November 5, 2009 by Rendril Quote
Burns Posted November 12, 2009 Report Posted November 12, 2009 (edited) i got another problem with stores... so far, i tried with Rendril's suggestion, and also did an array with Observer's help, but seemingly we are either too stupid, or foudn the borders of mur's anti-data-farming XD here's what i have: [php]@vs = mds_storage("namestore", toau); @storage[@vs] = uv('name'); @va = @storage[@vs]; echo @va; //Rendril's script @vb = array(uv('id') => uv('name')); Echo @vb[53832];] //Observer's script[/php] What it does: it echos my name, two times... not the name of any other id i enter, though, i guess for safekeeping reasons however, i want it to do something different: i want it to output a list of all people who clicked the object (and chose a certain way, but that's another issue i should be able to cover pretty easily)... is that possible, and if, how to do it? thanks for your help, hints, or whatever else you have for me XD Edited November 12, 2009 by Burns Quote
cutler121 Posted November 13, 2009 Author Report Posted November 13, 2009 (edited) Hey Burns, There are a few problems with what you coded, you aren't ever saving the associative array @vb so it won't be available for future calls. Also to store the names, you need to add them to an array not just save them to the variable. try this: @vs = mds_storage("namestore", toau); @va = @storage[@vs]; //@va stores the names and is an array //@va = array(); array_push(@va,uv('name')); @storage[@vs] = @va; foreach(@vn as @vk => @vv) { echo "<br>VN: @vk => @vv"; } //I changed the loop to foreach since it is easier to follow what is going on when you stored @va to mds_storage you had it set as a variable not an array which is why you will get an error if you try to push a new value onto it. If you find this is a problem, just uncomment the commented line above to change the variable to an array and run it once. That will reset the variable to be an array for the future. Just remember to comment it back again. This will store a list of who clicked your clickable in the order they clicked it. In addition to not storing the assiciative array, you are redefining the @vb array with: @vb = array(uv('id') => uv('name')); when what you want to do is add a new element like: @vb[uv('id')] = uv('name'); which creates a new key/value pair but doesn't delete all of the old data as well. Cheers, Cutler Edited November 13, 2009 by cutler121 Quote
Burns Posted November 13, 2009 Report Posted November 13, 2009 (edited) you are a genius, thanks a lot =)) i have made a few changes to the script to get just a list of people, not each person as often as they click the item, maybe it's going to be useful for someone else some time, too: [php]@vs = mds_storage("namestore", toau); @va = @storage[@vs]; //@va stores the names and is an array //@va = array(); if (!mds_has_rpcq_keys ('burns-store-test-key')) { array_push(@va,uv('name')); @storage[@vs] = @va; mds_give_rpcq_keys ('burns-store-test-key');} foreach(@va as @vk => @vv) { echo "<br> @vv";//VN: @vk => }[/php] what i can't do anymore with that code is reseting the array like before, with uncommenting the =array() line, and unset refuses to work, too :/ not too much of a problem of course, you can just use another variable to set a new array, or it won't happen to you at all i had to do it that way because it was _very_ annoying to get each name ten times, and my quest will require people to check the list several times... Thanks for your quick help =D ah, obviously Rendril is right there... a lot shorter now XD but i still can't delete the data in the array with your code :/ Edited November 13, 2009 by Burns Quote
Rendril Posted November 13, 2009 Report Posted November 13, 2009 (edited) A note on reseting the array, you could use: [code] if(@va == null) @va = array(); [/code] Though in reality it will never need to be executed more than once. This part[code] foreach(@va as @vk => @vv) { echo "<br> @vv";//VN: @vk => [/code] Is getting executed regardless of whether there is a key held or not, you can put it after the if-statement. Edited November 13, 2009 by Rendril 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.