The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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> Is there any vbulletin code that allows me to do this? Thanks, Jon |
#2
|
|||
|
|||
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. |
Благодарность от: | ||
Max Taxable |
#3
|
|||
|
|||
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. |
#4
|
||||
|
||||
Quote:
|
#5
|
|||
|
|||
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.
|
#6
|
|||
|
|||
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?
|
#7
|
|||
|
|||
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?
|
#8
|
|||
|
|||
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. |
#9
|
|||
|
|||
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. |
#10
|
|||
|
|||
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> |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|