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.

Using Random To Simulate Dice Rolls

Featured Replies

A game of roll the dice against a gambler

Content:
[code]
<br/>Roll the dice, winning is nice
<!-- content separator -->
[[name]] rolled<br />[[di1]] and [[di2]]<br />Total: [[sum]]
[/code]

[code]
@vp = array(rand(1, 6), rand(1, 6));//create player's dice rolls
@vg = array(rand(3, 6), rand(2, 6));//create gambler's dice rolls and give him a slight advantage :)
@vs[0] = @vp[0] + @vp[1];//sum of player's rolls
@vs[1] = @vg[0] + @vg[1];//sum of gamberl's rolls

@vk = 0;//intialize player counter, could support more players in the game
@tpl = array();//amke sure @tpl is clear
//assign values to @tpl
@tpl[@vk]['di1'] = @vp[0];
@tpl[@vk]['di2'] = @vp[1];
@tpl[@vk]['name'] = uv('name');
@tpl[@vk]['sum'] = @vs[@vk];

++@vk;//increment player counter
@tpl[@vk]['di1'] = @vg[0];
@tpl[@vk]['di2'] = @vg[1];
@tpl[@vk]['name'] = "Gambler";
@tpl[@vk]['sum'] = @vs[@vk];

mds_template(@content[1],@tpl,false,2,'style="width:180;border:1px solid"');//call template function
retrieve(@vd);//get the player's scorign array
if(@vd == null)//check if the score were initialized yet, if not, initiliaze them
@vd = array(0, 0, 0);
//check for wins, losses or draws and increment appropriate counter
if(@vs[0] > @vs[1])
{
echo "You have won!";
@vd[0]++;
}
else if(@vs[0] < @vs[1])
{
echo "You lost =(";
@vd[1]++;
}
else
{
echo "It was a tie";
@vd[2]++;
}
store(@vd);//save the player's progress
//output the score
echo "<br/><br/>Your progress against the gambler<br/>";
echo "Wins: " . @vd[0] . "<br/>Losses: " . @vd[1] . "<br/>Draws: " . @vd[2];
[/code]

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.