Welcome, Guest. Please login or register.
CrystalBallSoft Message Boards
News: Check out the CrystalBallSoft Blog.
Pages: [1]
  Print  
This topic has not yet been rated!
You have not rated this topic. Select a rating:
Author Topic: Controls and Arrays  (Read 287 times)
0 Members and 1 Guest are viewing this topic.
freakazoidjake
Civilian

Offline Offline

Posts: 3


« on: February 10, 2010, 04:44:38 PM »

Hi! I'm new to the forums, but I love CBLite and look forward to collaborating with you guys!  Grin

Well, I've done some programming before, but never in real basic... but I've figured out some code, but for some reason I get errors, and I was hoping that someone could help me figure this out, so here we go:


Code:
Dim roll As ArrayClass
Dim ac, modifiedRoll, crit, hit, critMiss, numDice As Double
Dim i As Integer
Dim output As String

'So here I'm trying to take three input parameters to determine how many dice to roll,
'then through control statements determine if it is a hit or miss.

roll = New ArrayClass
output = ""
numDice = RollDice(GetScriptParameter("param1"))
hit = RollDice(GetScriptParameter("param2"))
crit = 97
critMiss = 3
ac = RollDice(GetScriptParameter("param3"))

'Dice are rolled here
For i = 0 To (numDice -1)
roll.Append(RollDice("1d100"))
Next

For i = 0 To numDice
modifiedRoll = roll.Items(i) - ac

If modifiedRoll >= hit and roll.Items(i) < crit Then
output = output + Str(modifiedRoll) + " - " + "Hit!" + EndOfLine
 
ElseIf roll.Items(i) >= crit Then
output = output + Str(modifiedRoll) + " - " + "Critical Hit!" + EndOfLine
   
ElseIf roll.Items(i) <= critMiss Then
output = output + Str(modifiedRoll) + " - " + "Critical Miss!" + EndOfLine
 
Else
output = output + Str(modifiedRoll) + " - " + "Miss!" + EndOfLine
 
End If
Next

ReturnValue(output)

But for some reason, it throws up all over my ArrayClass. Anybody have any suggestions?
Logged
MrCryptic
Dice-Guru
Administrator
*****
Offline Offline

Posts: 285


"The point of a journey is not to arrive."


« Reply #1 on: February 10, 2010, 04:52:57 PM »

This may be an "Off by 1" error.
For i = 0 To numDice should probably be For i = 0 To numDice - 1

This is on line 22 right above modifiedRoll = roll.Items(i) - ac

Without the -1 I got out of bounds errors when running the script. With the -1 it ran without error.

Cool script, btw!


Code:
Dim roll As ArrayClass
Dim ac, modifiedRoll, crit, hit, critMiss, numDice As Double
Dim i As Integer
Dim output As String

'So here I'm trying to take three input parameters to determine how many dice to roll,
'then through control statements determine if it is a hit or miss.

roll = New ArrayClass
output = ""
numDice = RollDice(GetScriptParameter("param1"))
hit = RollDice(GetScriptParameter("param2"))
crit = 97
critMiss = 3
ac = RollDice(GetScriptParameter("param3"))

'Dice are rolled here
For i = 0 To (numDice -1)
roll.Append(RollDice("1d100"))
Next

For i = 0 To numDice - 1
modifiedRoll = roll.Items(i) - ac

If modifiedRoll >= hit and roll.Items(i) < crit Then
output = output + Str(modifiedRoll) + " - " + "Hit!" + EndOfLine
 
ElseIf roll.Items(i) >= crit Then
output = output + Str(modifiedRoll) + " - " + "Critical Hit!" + EndOfLine
  
ElseIf roll.Items(i) <= critMiss Then
output = output + Str(modifiedRoll) + " - " + "Critical Miss!" + EndOfLine
  
Else
output = output + Str(modifiedRoll) + " - " + "Miss!" + EndOfLine
  
End If
Next

ReturnValue(output)
Logged

Mr Cryptic
Upper Management
MrCryptic@support@crystalballsoft.com
freakazoidjake
Civilian

Offline Offline

Posts: 3


« Reply #2 on: February 10, 2010, 09:26:06 PM »

Why thank you! And thanks for the help, Works great!
Logged
freakazoidjake
Civilian

Offline Offline

Posts: 3


« Reply #3 on: February 12, 2010, 10:19:22 AM »

I just wanted to let you know that after GMing a session of my game, my Friends were sooo impressed with how smoothly the combat went. You should pay me for advertising. smile

My players thought that CrystalBall was amazing, and are considering buying it for themselves.

You guys have a great product, I will refer anyone I can. Great job, guys.
Logged
CrystalBallMac
The Emperor
Administrator
*****
Offline Offline

Posts: 737


"So be it.... Jedi"


WWW
« Reply #4 on: February 12, 2010, 12:14:46 PM »

Thank you!
Logged

Joseph Sharp
Developer
support@crystalballsoft.com
Pages: [1]
  Print  
 
Jump to:  


Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
XHTML | CSS | Aero79 design by Bloc