# I've made My first function using parameters!

I’m so proud of myself!

I just managed to make a function that use parameters. This open possibilities for a mechanics I’ve been trying to hack my mind in how to implement.

For example, a way to simule complex operations in the background while the player is making decisions (like a Do while?) .

This way I could make a game were, as the weeks go by, certain random events may happen. (Accidental encounters. Prices fluctuations, weather changing??)

Here is the link: Dice roller

I’m putting the code here, so you guys could point ways for me to improve/clean, well if you feel like to. lol

Here is the Code:

``````*label test_comb
*temp dice 0
*temp times 0
*temp total 0

This is a simple die roll algorithm. Made by Victoro because he needs to better his (nonexistent?) coding skills.

please Enter how many sides do your dice got (Ex. six)

*fake_choice
#two sides (like a coin)
*set dice 2
#four sides
*set dice 4
#six?
*set dice 6
#twenty?
*set dice 20
#A hundred?
*set dice 100
#lemme put it!
*input_number dice 2 999

please Enter how many times do your dice got to row?

*fake_choice
#Two times
*set times 2
#four times
*set times 4
#lemme put it!
*input_number times 2 20

*page_break

*comment "For" is a scene written as a
*comment For-like function. It receives
*comment a number and a name as
*comment parameters. the number is
*comment for the number of times a
*comment command must be repeated
*comment and the name is the
*comment command to be repeated.

*gosub For times "roll_dice" dice

The total of points accumulated is: \${total}

*page_break
*return

*label For
*params
*comment For(i=0; i<=x; i++)
*comment   DO {action}

Program: The number of parameters in this function is: \${param_count}

this function repeat \${param_1} times

this function executes the function" \${param_2} " each time it repeats.

*comment This function accepts other functions calls if you wish!

*temp count 0
*temp limit param_1
*label for_each
*if (count<limit)
*gosub {param_2} param_3
*set count +1

[i]The die row count is[/i]: \${count} time(s)

*gosub for_each

*return
*else

[i][b]end of For[/b][/i]

*return
*return

*label roll_dice
*params
*temp return
*rand return 1 param_1

Program: [i]The dice rolled[/i] \${return}

*set total + return
Summary: [b]The total points cumulated is[/b] \${total}

*return

*comment
*comment
*comment
``````
8 Likes

Very interesting. It would be cool if the FOR loop became a native feature in Choicescript.

1 Like