Ask Your Question
1

How to make a program that others can run with minimum fuss for Calc?

asked 2020-09-08 21:57:00 +0100

Fuligina gravatar image

updated 2020-09-09 23:49:02 +0100

I have a D&D group that uses spreadsheets to hold character data; I want to be able to run a program from within the spreadsheet, where we can use data from specific cells as inputs, and it spits out the result into the cell it's called in.

image description

I've got the program working so this works in the command line:

image description See? Put in 2, 10, 3, and 4, get out 20.

So the question is, what is the simplest way to make it so that I can do something in place of "SomehowCallMyProgram" to actually call the program? Does everyone who would use my program have to set up a Python IDE? Would it be simpler for other users if I wrote the program in BASIC instead python, as it currently is? And also, what do I replace "SomehowCallMyProgram" with to actually call the program?

Code here: image description

edit retag flag offensive close merge delete

Comments

Did you already try opening your existing execl document/s with LO and see if stuff still works? Best case, you do not have to change anything, if you did not use any "fancy" function/features.

igorlius gravatar imageigorlius ( 2020-09-09 01:41:22 +0100 )edit

@Fuligina, If you post an example from the file, it would be easier to understand the need. Edit your question and use the clip icon to attach.

Schiavinatto gravatar imageSchiavinatto ( 2020-09-09 02:30:18 +0100 )edit
2

I think "minimal fuzz" for everyone of your D&D group would be achieved by porting your "d&d_damage_calculator.py" into a macro or formula. But the decision depends a bit on preference and on the complexity of your python script. Could you attach the script so we can estimate how hard it would be to rewrite it as formula/maco?

igorlius gravatar imageigorlius ( 2020-09-09 23:32:11 +0100 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2020-09-10 00:12:20 +0100

igorlius gravatar image

updated 2020-09-10 02:01:35 +0100

Hello,

here is your programm as a BASIC macro. Just put it into Tools -> Macros -> "Edit Macros" and you can call it from inside any cell via

=DCALC(5,10,10,2)

Here the macro:

Function DIE(uBound As Double)
    DIE=(CInt(1.0 + Rnd() * (uBound - 1.0)))
End Function

Function DCALC(num1 as Integer, num2 as Integer, num3 as Integer, num4 as Integer)
    Randomize() rem init rnd seed with system timer
    Dim damage as Integer   
    damage = 0
    For i = 0 To num1
        damage = damage + DIE(num2)
    Next
    damage = damage + (num3*num4)
    DCALC=damage
End Function

Hope that helps.

To show the community your question has been answered, click the ✓ next to the correct answer, and "upvote" by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

Have a nice day and let's (continue to) "Be excellent to each other!"

edit flag offensive delete link more

Comments

Thank you, this is awesome! I appreciate the help. Except that when I use it, I just get num3*num4, so I'll see if I can fix that. Edit: Figured it out, just added a line to DIE: DIE=RndRange

Fuligina gravatar imageFuligina ( 2020-09-10 00:36:56 +0100 )edit

My Bad, i refactored the name and forgot that. I'll edit it.

igorlius gravatar imageigorlius ( 2020-09-10 01:59:26 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-09-08 21:57:00 +0100

Seen: 81 times

Last updated: Sep 10 '20