DocFlareon #1 Posted June 9, 2017 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$ Quote Share this post Link to post Share on other sites
carlsson #2 Posted June 9, 2017 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$ Quote Share this post Link to post Share on other sites
DocFlareon #3 Posted June 9, 2017 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! Quote Share this post Link to post Share on other sites
carlsson #4 Posted June 9, 2017 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). Quote Share this post Link to post Share on other sites
DocFlareon #5 Posted June 9, 2017 I'll tinker around a bit later on. I have it working nicely on Commodore BASIC v7 and Amiga( and HiSoft) BASIC. Now to get it to behave in Atari BASIC rev.C Atari BASIC's odd-ball string handling might cause issues. Quote Share this post Link to post Share on other sites
carlsson #6 Posted June 9, 2017 I can assert you that Atari BASIC doesn't seem to add leading spaces to numbers when printed or converted to strings. Quote Share this post Link to post Share on other sites