Jump to content
IGNORED

Dice Formatting Woes with BASIC 7


Recommended Posts

I'm building an RPG Assistant app for various systems, and I've come up on a stumbling block in Commodore BASIC v7.0 when it comes to formatting the output for rolling percentile dice in the form of 2 d10 (high die, low die). I can't figure out how to format the output the way I want it without slowing the system to a crawl via nine extra IF/THEN statements. What I want to show are dice rolls of 01-00(printed as 100). What I get instead is 0 1-0 0(printed as 100). The workaround(not using nine extra IF/THEN) that I've found has the unwanted behavior of not displaying the high die if it equals zero.

rem d100
dim va$(2):rem string array for output
x=0:rem high die
y=0:rem low die
x=int(rnd(0)*10):y=int(rnd(0)*10):rem rolling the dice
va$(0)=str$(x):va$(1)=str$(y):rem putting the dice rolls into a string array for output
vb$=str$((x*10)+y):rem workaround string
if x=0 and y=0 then print 100:else print va$(0)(1):rem print vb$

Link to comment
Share on other sites

Are you going to display the dice rolls separately somewhere else? Otherwise you could add the two rolls at once.

 

This code will display the range 01-100 without leading spaces:

VA$=MID$(STR$(X),2)+MID$(STR$(Y),2):IF VA$="00" THEN VA$="1"+VA$

Link to comment
Share on other sites

Are you going to display the dice rolls separately somewhere else? Otherwise you could add the two rolls at once.

 

This code will display the range 01-100 without leading spaces:

VA$=MID$(STR$(X),2)+MID$(STR$(Y),2):IF VA$="00" THEN VA$="1"+VA$

As the project extends along, I'll be printing die rolls where appropriate on character sheets, but for now I'm just getting the dice-rolling module working for output on the console.

 

That being said, your line of code worked rather well. Thank you!

Link to comment
Share on other sites

Since you happen to know that each RND statement will generate a number 0-9, possibly you could use RIGHT$(STR$(X),1) instead of MID$. I don't know if it is any quicker though, and the MID$ variant is more universal as it just skips the leading space generated by STR$ (and PRINT, I think it uses part of the same routine).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...