RPTools.net

Discussion and Support

Skip to content

It is currently Mon May 20, 2013 7:32 am 






Reply to topic  [ 13 posts ] 

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
Dragon
 
Joined: Wed Nov 15, 2006 9:03 am
Posts: 987
 Post subject: Foreach (Or bolding going where i've never gone)
PostPosted: Mon Apr 30, 2012 5:52 pm 
So I'm making a framework for Ars Magica that has a slightly odd mechanic in it: Botch dice.

What i need to do is roll Xd10, and count the number of 0's (or 10s as the case may be). What i have so far is:

Code:
[foreach(i,BotchDice,"<br>"),Code:
{
[t:BotchRoll=d10]
}
]


After a simple input for the number of dice to be rolled, however it's only ever rolling 1d10, no matter what the number of BotchDice is.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Sep 11, 2007 6:31 pm
Posts: 5228
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Mon Apr 30, 2012 6:07 pm 
aku wrote:
So I'm making a framework for Ars Magica that has a slightly odd mechanic in it: Botch dice.

What i need to do is roll Xd10, and count the number of 0's (or 10s as the case may be). What i have so far is:

Code:
[foreach(i,BotchDice,"<br>"),Code:
{
[t:BotchRoll=d10]
}
]


After a simple input for the number of dice to be rolled, however it's only ever rolling 1d10, no matter what the number of BotchDice is.


foreach iterates over an array of things, if you are prompted for BotchDice, then it's a simple string. You should likely be using COUNT instead.... Also, I would highly suggest assigning to a temp variable and passing that as your "max" variable instead of relying on the input "results".

_________________
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..


Top
 Profile  
 
User avatar  Offline
Demigod
 
Joined: Mon Jun 29, 2009 9:37 am
Posts: 2683
Location: Germany
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Tue May 01, 2012 12:41 am 
You might be interested in my Ars Magica framework (5th edition) - at least to look what i've done. I prepared it for another setting, so I did not code any magic stuff into it.

You can find it here.

EDIT: forgot to say... feel free to rip it apart and use every part you find useful.

_________________
"Cif's html works" (confirmed by independent studies)

most complete list of my maptool stuff


Last edited by CoveredInFish on Tue May 01, 2012 9:04 am, edited 1 time in total.

Top
 Profile  
 
User avatar  Offline
Dragon
 
Joined: Tue Aug 23, 2011 10:41 am
Posts: 770
Location: Cornwall, UK
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Tue May 01, 2012 8:50 am 
What you want to do doesn't really require foreach:

Code:
[hrollList ""]
[
h, for(i,0,noOfRolls), code :{
[
hrollList listAppend(rollList,roll(1,10))]
}]
[
hnoOfZeros listCount(rollList)]
[
houtput(noOfZeros)] 


As an alternative using [for:].

_________________
I'm working on adapting the Alternity game for MapTool, but it's on the back burner unless anyone shows any interest except for me. Current release & support thread: [Alternity] v0.2 *BETA*


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 5488
Location: Netherlands
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Tue May 01, 2012 10:30 am 
Bone White wrote:
What you want to do doesn't really require foreach:

Code:
[h: rollList = ""]
[
h, for(i,0,noOfRolls), code :{
[
h: rollList = listAppend(rollList,roll(1,10))]
}]
[
h: noOfZeros = listCount(rollList)]
[
h: output(noOfZeros)] 


As an alternative using [for:].


that aint gonna work. The result will be always noOfRolls.
I think you meant:
Code:
[h: rollList = ""]
[
h, count(noOfRolls):rollList = listAppend(rollList,roll(1,10))]
[
h: noOfZeros = listContains(rollList, 0)]
Number of zeros rolled: {noOfZeros}
  

_________________
My stuff
Excel Tools: Table editor and Illumination Generator
MT Tools: Dungeon Builder Tool, Bag of Tricks: Teleport pads, Pits, Traps and Warded Areas and onMouseOverEvent
Framework: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade and Only War
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow

My dropbox referral. If you use this then both you and me get 500Mb extra space. 2.5Gb total.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 5303
Location: Bay Area
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Tue May 01, 2012 12:08 pm 
If all you care about is the botch count, then you can use the XdYsT dice expression:

Code:
[H: abort(input("numDice|1|How many Botch Dice?|TEXT"))]
[
R, if(isNumber(numDice)): strformat("Botch Dice Rolled: %{numDice}<br>Number of Botches: %s",eval(numDice+"d10s10")); 
   
"You must enter a valid number."] 

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 5303
Location: Bay Area
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Tue May 01, 2012 1:04 pm 
wolph42 wrote:
Bone White wrote:
What you want to do doesn't really require foreach:

Code:
[h: rollList = ""]
[
h, for(i,0,noOfRolls), code :{
[
h: rollList = listAppend(rollList,roll(1,10))]
}]
[
h: noOfZeros = listCount(rollList)]
[
h: output(noOfZeros)] 


As an alternative using [for:].


that aint gonna work. The result will be always noOfRolls.
I think you meant:
Code:
[h: rollList = ""]
[
h, count(noOfRolls):rollList = listAppend(rollList,roll(1,10))]
[
h: noOfZeros = listContains(rollList, 0)]
Number of zeros rolled: {noOfZeros}
  

Actually, this wouldn't work either. You would either have to change the roll (1-10 to 0-9) or what you're checking for in the list (change 0 to 10).

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Dragon
 
Joined: Tue Aug 23, 2011 10:41 am
Posts: 770
Location: Cornwall, UK
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Tue May 01, 2012 1:26 pm 
Even the simplest of macros can throw us, which is why extensive testing is required!

Don't lose heart though, I love learning, and should learn to test code I post to make sure it's correct...

_________________
I'm working on adapting the Alternity game for MapTool, but it's on the back burner unless anyone shows any interest except for me. Current release & support thread: [Alternity] v0.2 *BETA*


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 5488
Location: Netherlands
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Tue May 01, 2012 4:58 pm 
aliasmask wrote:
wolph42 wrote:
Bone White wrote:
What you want to do doesn't really require foreach:

Code:
[h: rollList = ""]
[
h, for(i,0,noOfRolls), code :{
[
h: rollList = listAppend(rollList,roll(1,10))]
}]
[
h: noOfZeros = listCount(rollList)]
[
h: output(noOfZeros)] 


As an alternative using [for:].


that aint gonna work. The result will be always noOfRolls.
I think you meant:
Code:
[h: rollList = ""]
[
h, count(noOfRolls):rollList = listAppend(rollList,roll(1,10))]
[
h: noOfZeros = listContains(rollList, 0)]
Number of zeros rolled: {noOfZeros}
  

Actually, this wouldn't work either. You would either have to change the roll (1-10 to 0-9) or what you're checking for in the list (change 0 to 10).


Bone White wrote:
Even the simplest of macros can throw us, which is why extensive testing is required!

Don't lose heart though, I love learning, and should learn to test code I post to make sure it's correct...


Lol!! Well at least we've reinforced the current hiarchy of coding skills :mrgreen:

_________________
My stuff
Excel Tools: Table editor and Illumination Generator
MT Tools: Dungeon Builder Tool, Bag of Tricks: Teleport pads, Pits, Traps and Warded Areas and onMouseOverEvent
Framework: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade and Only War
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow

My dropbox referral. If you use this then both you and me get 500Mb extra space. 2.5Gb total.


Top
 Profile  
 
User avatar  Offline
Dragon
 
Joined: Tue Aug 23, 2011 10:41 am
Posts: 770
Location: Cornwall, UK
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Wed May 02, 2012 6:44 am 
Well, if it wasn't for my mistakes, you two couldn't shine (and out-shine) each other, so if it wasn't for me you wouldn't look as good 8)

_________________
I'm working on adapting the Alternity game for MapTool, but it's on the back burner unless anyone shows any interest except for me. Current release & support thread: [Alternity] v0.2 *BETA*


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 5488
Location: Netherlands
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Wed May 02, 2012 6:54 am 
Bone White wrote:
Well, if it wasn't for my mistakes, you two couldn't shine (and out-shine) each other, so if it wasn't for me you wouldn't look as good 8)


which is why we have this code skill hiarchy... to make me look good 8) :mrgreen:

_________________
My stuff
Excel Tools: Table editor and Illumination Generator
MT Tools: Dungeon Builder Tool, Bag of Tricks: Teleport pads, Pits, Traps and Warded Areas and onMouseOverEvent
Framework: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade and Only War
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow

My dropbox referral. If you use this then both you and me get 500Mb extra space. 2.5Gb total.


Top
 Profile  
 
User avatar  Offline
Dragon
 
Joined: Wed Nov 15, 2006 9:03 am
Posts: 987
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Thu May 03, 2012 9:18 am 
my oh my, where as this thread gone over the course of a few days. So, count mostly works, although, i'm thinking of packaging the numbers i get into an array, and passing that through a for each, to generate a simple, "you botch with X dice" or "You dont botch"...


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 5303
Location: Bay Area
 Post subject: Re: Foreach (Or bolding going where i've never gone)
PostPosted: Thu May 03, 2012 9:56 am 
aku wrote:
my oh my, where as this thread gone over the course of a few days. So, count mostly works, although, i'm thinking of packaging the numbers i get into an array, and passing that through a for each, to generate a simple, "you botch with X dice" or "You dont botch"...

Don't forget to take a look at this solution.

_________________
Downloads:


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 13 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 2 guests





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman