skyvory / vn-canvas

Automatically exported from code.google.com/p/vn-canvas
0 stars 1 forks source link

Would there be a method to generating a random number for a variable? #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I was looking around online for a html VN engine last night and came across 
this and started reading over the documentation. so far I haven't came across 
anything with regards to generate a random number and sets that to a variable. 
I'm I just blind or could there be a workaround or could this be something 
added in the future?

I've been recently making a VN for the VNDS engine, but not everyone has a 
Nintendo DS or Android device >.<;;. A good majority of the devices support 
HTML5, so this looks to be pretty awesome.

Thanks!
Joshua

Original issue reported on code.google.com by joshuaca...@gmail.com on 9 May 2012 at 12:35

GoogleCodeExporter commented 9 years ago
I was also looking to see if there was any form of IF function, which I saw the 
example under set:

set, {$var6:false},
    jump, {var6:true},
    /* jump is not executed because var6 is false */

That would work with a good portion of the vn's IFs i'm working on, but could 
the engine support something like this:

set, {var2:90}
set, {var3:1}
    jump, {var2:>=90}, {var3:1}, 

The jump function is evaluated on two conditions. The first being var2 is more 
than or equal to 90 and var3 is 1.

Thanks again,
Joshua

Original comment by joshuaca...@gmail.com on 9 May 2012 at 1:11

GoogleCodeExporter commented 9 years ago
Hi Joshua,

Currently, there's no random value generator. Or a multiple condition jump. 
Workaround is to use a macro, which executes custom javascript. You can use 
Helper.setValue and Helper.getValue methods.

For example:
function macro_random()
{
     /* generate random value from 1 to 10 */
     Helper.setValue("random_var_name", Math.floor((Math.random()*10)+1))
}

then in script:
set, {"random_var_name", 0},     /* create variable */
macro, "macro_random",

You can do something similar to multiple condition jumps, by creating a macro 
that reads variable values, perform logic, then set the result to another 
variable. Then in the script, use this result variable as parameter to "jump".

Will consider adding these on future revisions. Shouldn't be too hard. I think 
:)

Thanks!

Original comment by oclabbao on 15 May 2012 at 3:52

GoogleCodeExporter commented 9 years ago
Oh, sorry about the example, mistyped that one. 'jump' should have a label to 
jump to.

set, {$var6:false},
jump, {var6:true},
/* jump is not executed because var6 is false */

This should have read:
set, {$var6:false},
jump, {var6:true, label:"some_label_to_jump_to"},
/* jump is not executed because var6 is false */

See 'jump' for samples on conditional jumps and also loops.

Original comment by oclabbao on 15 May 2012 at 4:04

GoogleCodeExporter commented 9 years ago
Managed to squeeze some time and implement the above (yey!). I'm not ready to 
release a revision yet though, so if you want to try it out, please checkout 
the latest source from SVN.

To use:
set, {var1:"random"},       /* generate random float between 0 and 1 */
set, {var1:"random 10 20},  /* generate random integer between min and max 
values */
jump, {label:"label1", var1:10, var2:20}  /* jump to label1 if ALL conditions 
are true */

Thanks! Keep the issues/requests coming! :)

Original comment by oclabbao on 16 May 2012 at 12:40

GoogleCodeExporter commented 9 years ago
xD Very awesome! I'll let you know if I run into any other possible requests.

Thanks!

Original comment by joshuaca...@gmail.com on 16 May 2012 at 10:40

GoogleCodeExporter commented 9 years ago

Original comment by oclabbao on 31 Jan 2013 at 8:11