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.

Time: Check If Person Took Too Long

Featured Replies

  • Root Admin

[code]// first object

@vd = time();
// gets time in seconds and sets it to a variable
store(@vd);
// stores the variable into whever

-------------

// object two

retrieve(@vd);
// Gets the time we stored in object one
if((@vd + 10 * 60) < time() ){
// first it gets the first time, and adds 10 * 60 onto it (which is 10 minutes) then
// compares it with current time. If current time is bigger than the sum you calculated
// then it will be over the 10 minutes and it displays the apropiate text
echo "sorry you are too slow";
}else{
echo "you win the game!";
}[/code]

time() will retrive the current time (for more techincal people its actually a unix timestamp) Basicly in seconds from a certain event.
This is not easily readable by people as its returned in seconds but for this example its great.

NOTE: i dont have mdscript, nor will i ever since i dont quest, so this is all vague guessings from documentation and my knowledge of php.
I know php, so techincally it should work...

Any questions or if someone wants to test it, Go ahead

This is just an example, You will need to make sure that @vd is set already from the first object but i left that out as it clouds the example

Edited by Chewett

uhmm... i know i'm not supposed to post here, but you have a little mistake there, you have @vh once where it should be @vd [at least i think so O_o]

and, i have a question there, too:
will that piece of code work for several players who are attempting at once?
or would the dead-line expire ten minutes after the first person activated the timer, and stay dead until i manually reset the timer?

i'm not much of a coder, so you'll have to put up with such newbish questions for some time... XD

Nice code Chewett, but I think you mean @vh [b]+[/b] 10 * 60
Otherwise it would be checked in the next 6000 years or so :)

Burns, regarding the scope of the storage. It will work for each user seperately, we are waiting for multiple types to be supported. Also you're right about the @vh needing to be @vd.



This example performs the same logic checks as above and shows how to calculate the remaining time.
It gives the user 14 hours to save the world.

Object1:
[code]
@vz = "rendrilrevant-";//define key prefix
retrieve(@vt);//get timer data
//check if the player started the timer already
if(mds_has_rpcq_keys(@vz . "timer-started"))
{
@vd = floor((@vt - time())/60 / 60);//get remaining time by subtracting current tiem from given time length
echo "You only have " . @vd . " hours to sa"."ve the earth!";
}
else
{
//calculate given tiem by adding 14 hours (50400 seconds) to current time
@vt = time() + (14 * 60 * 60);
//flag that timer has started
mds_give_rpcq_keys(@vz . "timer-started");
//store time value
store(@vt);
echo "You have 14 hours to sa"."ve the earth!<br />Run! Run like the wind!";
}
[/code]


Object2
[code]
@vz = "rendrilrevant-";//define key prefix
//check if timer was started yet
if(mds_has_rpcq_keys(@vz . "timer-started"))
{
retrieve(@vt);////get timer data
//check if current time is less than or equal allowed time
if(time() <= (@vt))
{
//perform actions if successful
mds_give_rpcq_keys(@vz . "world-sav"."ed");
echo "Well done you sav"."ed the earth!<br />Now go to something con"."structive.";
}
else
{
//perform actions if not successful
mds_give_rpcq_keys(@vz . "world-not-sa"."ved");
echo "You were unable to sa"."ve the earth =(";
}
//clean up the timer key
mds_take_rpcq_keys(@vz . "timer-started");
}
[/code]

Edited by Rendril

hmmmm... could you also post a version of it ready to go into the items? because currently rendril i can't get the first code to work.... i removed the comments.... and it says unexpected end on line 15, which is this:


echo "You have 14 hours to sa"."ve the earth!<br />Run

Strange, I just tested it and it works fine.
Here it is without comments, see if that helps:
[code]
@vz = "rendrilrevant-";
retrieve(@vt);
if(mds_has_rpcq_keys(@vz . "timer-started"))
{
@vd = floor((@vt - time())/60 / 60);
echo "You only have " . @vd . " hours to sa"."ve the earth!";
}
else
{
@vt = time() + (14 * 60 * 60);
mds_give_rpcq_keys(@vz . "timer-started");
store(@vt);
echo "You have 14 hours to sa"."ve the earth!<br />Run! Run like the wind!";
}
[/code]

  • Author
  • Root Admin

[quote name='Burns' date='29 October 2009 - 04:03 PM' timestamp='1256832209' post='46069']
uhmm... i know i'm not supposed to post here, but you have a little mistake there, you have @vh once where it should be @vd [at least i think so O_o]
[/quote]

Thanks Burns, i changed that

[quote name='Rendril' date='29 October 2009 - 04:16 PM' timestamp='1256833008' post='46070']
Nice code Chewett, but I think you mean @vh [b]+[/b] 10 * 60
Otherwise it would be checked in the next 6000 years or so :D
[/quote]

and perhaps i might want it to be checked within the next 6000 years :)

changed also, thanks

Did anyone test it? since i cant actually check as i have no access...

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.