vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Randomly running some code (https://vborg.vbsupport.ru/showthread.php?t=303779)

Jon12345 10-24-2013 11:12 AM

Randomly running some code
 
I have some ad code, but only want to show it with a 1 in 10 chance. The code is:

Code:

<div data-type="ad" data-publisher="abc.mysite.site" data-zone="ron" data-format="728x90"></div>
It will be in my postbit legacy template.

Is there any vbulletin code that allows me to do this?

Thanks,

Jon

kh99 10-24-2013 12:36 PM

I think this would work:
Code:

<if condition="TIMENOW%10==0">
<div data-type="ad" data-publisher="abc.mysite.site" data-zone="ron" data-format="728x90"></div>
</if>


Basically, whenever the current time (in seconds) ends in 0 it will show.

Jon12345 10-24-2013 12:42 PM

Clever idea, thanks! I will try that. :)

--------------- Added [DATE]1382625240[/DATE] at [TIME]1382625240[/TIME] ---------------

Seems to work. :) Would be nice to work out how to vary the probability of display. e.g 1 in 7 or whatever. So, I could say decide to set it to 1 in 7 or 1 in 5 etc.

squidsk 10-24-2013 03:15 PM

Quote:

Originally Posted by Jon12345 (Post 2455850)
Clever idea, thanks! I will try that. :)

--------------- Added [DATE]1382625240[/DATE] at [TIME]1382625240[/TIME] ---------------

Seems to work. :) Would be nice to work out how to vary the probability of display. e.g 1 in 7 or whatever. So, I could say decide to set it to 1 in 7 or 1 in 5 etc.

Switch the number (i.e. 10) after the % to whatever you want, so 1 in 7 change the 10 to a 7, 1 in 5 change the 10 to a 5.

kh99 10-24-2013 06:08 PM

Yeah, what squidsk said. I simplified the explanation a little, the code actually divides the unix time (seconds since Jan 1 1980 or something like that) by ten and checks that the remainder is 0, which happens when the last digit is 0 (since we're dividing by 10). But you can just as easily divide by 7 (or whatever) and check for a remainder of 0 to get a 1 in 7 chance.

Jon12345 10-25-2013 12:31 PM

I've tried using 2 and it showed my ads 1 in 2 chance. But when I tried 4 or 7, it didn't show 1 in 4 or 1 in 7 times. Maybe the maths is a bit out somehow? Do I need to clip off the decimals or something?

kh99 10-25-2013 12:42 PM

Hmm...'%' should divide integers and return the remainder, so I don't think decimals should matter. So you're saying condition="TIMENOW%7==0" doesn't work right?

Jon12345 10-25-2013 01:02 PM

I am trying 1 in 4 right now. TIMENOW%4==0

See it in action (or not as the case may be!):http://access-programmers.co.uk/foru...ar#post1301767

The third post has a 300x250 advert. There should be another one appearing to the right of that one 1 in 4 times. But it doesn't.

kh99 10-25-2013 01:22 PM

OK, I ran a test and it seems to work. Are you saying that the exact code works with 10 or 2 but not 4 or 7 (I guess I'm saying, are you sure there's not a typo)? If you do this (add the 1|| in the condition):
Code:

<if condtion="1||TIMENOW%4==0">
Ad code
</if>


then it should show every time and you can make sure there's not something else wrong.

The only other thing I can think of is that it's not exactly random because it's based on the time, so if for example you have it set to 4 and you constantly hit reload, and the page happens to take about 4 seconds to load each time, you may end up with something that looks like it's not a 1 in 4 chance.

Jon12345 10-25-2013 02:16 PM

My code is:

Code:

<if condition="TIMENOW%4==0">
<td>
<div data-type="ad" data-publisher="xxx.mysite.site" data-zone="ron" data-format="300x250"></div>
</td>
</if>

I got it to show 2 out of 13 goes. Maybe I was just unlucky with my first few tries. I will try 1 in 3. :)


All times are GMT. The time now is 04:58 PM.

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.01090 seconds
  • Memory Usage 1,738KB
  • 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
  • (4)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete