Skip to content
View in the app

A better way to browse. Learn more.

MagicDuel Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Storing Troubles

Featured Replies

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 by dst

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 by Grido

  • Author

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 by dst

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]

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.

  • Root Admin

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

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 by awiiya

  • Author

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 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. :)

  • Root Admin

[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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Forum Statistics

  • Total Topics 17.5k
  • Total Posts 182.2k

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.