Jump to content
Sign in to follow this  
Rendril

Using A Storage To Log A User's Quest Progress

Recommended Posts

This script will log a user's progress through various parts of a quest.
In this example we store the user's name, their age at the time of completing the stage, the MD day that it was completed and the current progress.
Note that anything can be kept in a storage, and here it is done with array.
It would be better to store the timestamp rather than only a day but I keep it simple for the sake of demonstration.
When picking a storage name, make it descriptive and try to reuse where possible.
Storage type depends on your needs for the quest, in most cases it will be aoau or toau.

[code]@vi = 123456790;//your ID, see the limiting access to a quest by id thread for more ideas
@vs = mds_storage("storage-name","storage-type");//get the id of the storage
if(@storage[@vs] == null)@storage[@vs] = array(); //initialize storage array
if(uv('id') != @vi)//check whether it is a participant or quest creator
{
@vp = 3;//progress for this stage of the quest

//create an array storign the particulars you want recorded
@temp = array('name' => uv('name'),
'age' => uv('age'),
'day' => date('z'),
'progress' => @vp);

@storage[@vs][uv('id')] = @temp;//save the array to the storage
echo "you have completed stage " . @vp . "!";
}
else{
//echo the desired info for you to see
foreach(@storage[@vs] as @vl){
echo @vl['name'] . " reached stage " . @vl['progress'] . " on day " . @vl['day'] . " with " . @vl['age'] . " active days<br />";
}
}[/code]

Various other checks can be done such as preventing the user from repeating a quest by the use of keys.
I eliminated duplicate entries for the same user here, but you might want ot log ALL tries the user has had. Edited by Rendril

Share this post


Link to post
Share on other sites
If using this and leaving the comments in, put a . in the following words;
Line 1 - "thread" contains 'read'
Line 13 - "save"
Line 17 - "info" - 'INF'


Also, Ren i get a "[b]eval()'d code[/b] on line [b]18"[/b]
In case it's me, the only bit i changed (other than the .'s)was
("storage-name", "storage-type") to
("gridotest123", "aoau")

Share this post


Link to post
Share on other sites
comments removed, error still there[b]

Warning[/b]: Invalid argument supplied for foreach() in [b]/home/magicdue/public_html/dlg/dlg.rpcqdocread.php(136) : eval()'d code[/b] on line [b]15[/b]

Line 15;
foreach(@storage[@vs] as @vl){ Edited by Grido

Share this post


Link to post
Share on other sites
strangely enough, i don't get that issue...
all i did was deleting all comments, insert a few names and my id, and it works...

you might need to run your script without setting your id as vi once, foreach gives errors when the array is empty, and Chewie kindly told me, try and do a debug on it, if your have NULL in your array, that's the reason for it to fail

"debug(@storage[@vs]);"

very handy, and working, script, thanks =)

edit: yeah... rendril solves things a lot more eloquent, and does so while i try and type things... XD Edited by Burns

Share this post


Link to post
Share on other sites

That now works, even with my modifications :D

Is it possible to get a delete function? So that well, entries can be deleted or cleared, so you can use the same storage again

Share this post


Link to post
Share on other sites

Remember that the storage simply holds a variable.

You could erase it with something like this, akin to initializing:
[code]
@vs = mds_storage("storage-name","storage-type");
@storage[@vs] = null;
[/code]

Link it with a form to trigger on the click of a button and you can make a nice admin interface :D

Share this post


Link to post
Share on other sites

That would delete all? Or per item in the list? Cos i'd like to be able to delete by item
And does it matter where i put that?

Also, odd request, where would i put about if the information retunred was null, not telling me the blank information?

I want a nice admin interface, but i might work on that once i have all the ''essentials'' sorted first :D

Share this post


Link to post
Share on other sites

[quote name='Grido' date='07 December 2009 - 12:11 AM' timestamp='1260144709' post='49334']
That would delete all? Or per item in the list? Cos i'd like to be able to delete by item
And does it matter where i put that?

Also, odd request, where would i put about if the information retunred was null, not telling me the blank information?

I want a nice admin interface, but i might work on that once i have all the ''essentials'' sorted first :D
[/quote]

I used several different kinds of user data storage in some of my recent quests. If you look at my "what number am I WP Quest" at the talking rock, one of the options is a stats page which tells how many times people have completed each leg of this quest. For this I used a simple numbered array for the 12 legs and then a few higher array entries to store things like names of people who completed the quest, etc. If you want to zero out an entry you can always just change the value of the particular entry you want changed, you don't need to reset the entire storage.


@vl = mds_storage("whatnum-storage-all",'aoau');
@vs = @storage[@vl];

// @vs[15]="";
// @vs[1]= 0;

I used the 1-12 to store how many people solved each of the 12 legs and then [13] to record how many people completed the quest. [14] stored the names of the people completing the quest so I could echo it out later. [15] stored the name of the first person to win a WP, so I had to clear it out a few times to test the routines which is why I have that line commented out. You should also remember that PHP arrays start at [0] not [1] so I stored how many different people had started my quest there (up to 238 as of today).

If you use a simple array like this, it can make printing out your results easy since you can use loops as well, for example:


for(@va=1;@va<13;@va++){
echo @vs[@va];
if(@vs[@va] == 1){echo " person ";}
else{echo " people ";}
echo "completed clue ".@va."<br>";
}


In my astral plane quests, I used the same idea, but used an associative array since there were many different elements I wanted to keep track of and key value pairs can make it easier to see what the storage is for.

Cheers,

Cutler

PS if you update the array, don't forget to put the storage save command somewhere near the bottom of your code. Also make sure you don't change the value of the location reference (@vl) or it won't work.

@storage[@vl]=@vs;

Edited by cutler121

Share this post


Link to post
Share on other sites

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

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Forum Statistics

    15,831
    Total Topics
    173,481
    Total Posts
  • Recently Browsing

    No registered users viewing this page.

  • Upcoming Events

    No upcoming events found
  • Recent Event Reviews

×
×
  • Create New...