vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   counting time from a user action (https://vborg.vbsupport.ru/showthread.php?t=206016)

Vaupell 02-20-2009 02:09 PM

counting time from a user action
 
i want to count 10 minuttes from a action.

A user clicks a botton / or another event happens that triggers a timestamp
to be marked.

how would i go about counting 10 minuttes, and activate a trigger after
those 10 minuttes ?

sort of a delay, and perhaps ewen if the user hits refresh
the display would just show something like 5minuttes togo.

all i need is the counting, i have no clue or no idea where to begin. ;)

Dismounted 02-21-2009 03:31 AM

And this is used for?

vbplusme 02-21-2009 04:13 AM

I think you might need to use a javascript function to get were you want to go.

TigerC10 02-21-2009 05:34 AM

Quote:

Originally Posted by vbplusme (Post 1750409)
I think you might need to use a javascript function to get were you want to go.

That would require a user to stay on the page for 10 minutes and not navigate away. Very not cool from a design standpoint.

Quote:

Originally Posted by Vaupell (Post 1749927)
A user clicks a botton / or another event happens that triggers a timestamp to be marked.

Very easy to add a timestamp to a database.

Quote:

Originally Posted by Vaupell (Post 1749927)
how would i go about counting 10 minuttes, and activate a trigger after
those 10 minuttes ?

Not very easy to make a "trigger" after 10 minutes. You might consider using what's known as a CRON job. CRON jobs are scripts that get executed every 5/10/15/30/60/1440 minutes. There's no real way to guarantee that the trigger will be executed exactly 10 minutes after someone sets the timestamp - the cron job will just run at the set intervals. So if someone initaties the trigger right before your cron job runs - then the script will pass them over since it hasn't been 10 minutes for them. They may have to wait 12 minutes, or even 15... All the way up to 19 minutes for the next cron job script to come along and unset the delay.

Quote:

Originally Posted by Vaupell (Post 1749927)
sort of a delay, and perhaps ewen if the user hits refresh
the display would just show something like 5minuttes togo.

Okay, hang on. Do you want a trigger or do you just want a delay? Because delays are much easier...

Say you've got a table in the database called "delay_timestamps"... It would have the fields "userid" and "timestamp".

Insert or update the field with the user like so
PHP Code:

$db->query_write("INSERT INTO ".TABLE_PREFIX."delay_timestamps (userid, timestamp) VALUES ".$userid.", ".time() );
// or...
$db->query_write("UPDATE ".TABLE_PREFIX."delay_timestamps SET timestamp=".time()." WHERE userid=".$userid );


// OR even better - this handles insert and update in 1 SQL statement
// but you have to set the userid field in the table as the key
// shouldn't be a problem since userids should be unique anyway

$db->query_write("INSERT ON DUPLICATE KEY UPDATE INTO ".TABLE_PREFIX."delay_timestamps (userid, timestamp) VALUES ".$userid.", ".time() ); 

Then in your "refresh" page you'll want to have a look see at the timestamp in the database and compare it with the current time:

PHP Code:

$wait_time 5// set the wait time they have before accessing the page again

$current_time time();

$user_timestamp $db->query_first("SELECT timestamp FROM ".TABLE_PREFIX."delay_timestamps WHERE userid=".$userid );

$number_of_seconds_since_stamp $current_time $user_timestamp;

$minutes_since_timestamp $number_of_seconds_since_stamp 60;

if(
$minutes_since_timestamp $wait_time)
{
     echo 
'Sorry, you still have '$wait_time-$minutes_since_timestamp .' minutes left...';
}
else
{
     echo 
'How sweet, you waited for me!';



This, of course, isn't the exact code you'll want... Certainly you'll want to condense the code down, like the $number_of_seconds_since_stamp variable is totally worthless - you can just divide by 60 on the fly. The timestamp variable in the database should probably be of type INTEGER, be careful not to use something like SMALLINT because it's not big enough for the timestamp. However, this will require an action from your user - it's not a trigger. It will require the user to click refresh, or to view the page again in some way.

You might be able to work out some AJAX thing that starts up on every single page that checks for the time remaining and then starts an auto-refresh count down... But it'd be kinda wasteful in my opinion. Plus, some browsers disable the javascript redirects/refreshes.

vbplusme 02-21-2009 07:14 AM

At this point, I am with DM and wondering now what the problem is that needs to be solved?

TigerC10 02-21-2009 10:39 AM

Quote:

Originally Posted by vbplusme (Post 1750471)
At this point, I am with DM and wondering now what the problem is that needs to be solved?

Eh, I guess I'm a programmer at heart. I don't care what I program, I just need a directive. Haha.

But, judging from his recent posts, it looks like he's trying to set a timer on submitting scores to ibProArcade - maybe to prevent cheating...

vbplusme 02-21-2009 12:24 PM

Got it. Now, it makes a lot of sense to me, thanks for that update.

Vaupell 02-23-2009 04:45 PM

hi guys, hehe well i have made a small textbased rpg game like the ones you know from
around the web and facebook, but running on vbulletin.
but needed somekind of limit of actions :D turns pr day or turns pr hour,
and thought well turns pr 10 minuttes would be the way to go.

but got stuck on another project so havent been looking into it the lasy couple of days.


All times are GMT. The time now is 09:13 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01536 seconds
  • Memory Usage 1,744KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete