Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Leon's Timer Test.tws

Hi....

I am really new to this subject of javascript and coding so forgive me if I ask stupid questions.

I am messing around with Leon's Timer Test.tws and learning a lot in the process.

What I want is to do is to change <<start_timer 10>> to a random number between 10 and 30 seconds.

I tried assigning <<set $tm = Math.floor(Math.random()*30+10)>> and passing $tm to <<start_timer $tm>> but I am getting nowhere.

What am I doing wrong or not doing please?

Comments

  • I'm nowhere near an expert on this subject, and since TheMadExile hasn't answered yet, I'b be glad to give it a look. I've looked on Leon's site but couldn't find the .TwS file you mentioned. Also, when more knowledgeable people read your post their going to ask you what story header your using, (Sugarcane, SugarCube ect..). Without knowing that it really is difficult to answer most peoples questions. Though, I will say that if you are using SugarCube (which I see no reason why anybody wouldn't), I'd try using it's better and less obtuse <<random>> macro, like this
    <<set $tm = random(10, 30)>>
  • When you ask for help, please don't make it a guessing game.  As noted by EcnelOvelam, you should always specify what story format you're using.  You should also always provide the code you want help with (if it's yours) or links to the code (if it isn't yours; and no "Leon's Timer Test.tws" is not sufficient, luckily Google turned up the answer).

    On to the problem you're having.  What you're trying to do isn't working for two reasons.
    [list type=decimal]
    You are very likely using a vanilla story format (probably Sugarcane).  The vanilla story formats' macro processor does not automatically provide support for $variables used as arguments to macros.
    The specific macros you're working with (from Timer Test.tws) do not natively support the use of $variables as arguments to them.

    End result: You cannot use $variables directly with the combination of macros you're using and the story format you're using them with.


    Possible workarounds:
    [list type=decimal]
    Use &lt;&lt;print&gt;&gt; to pre-reference your $variables.
    Modify the macros to support $variables as arguments.

    #1 would probably be easiest for you to accomplish and could be done like so: (n.b. random() has been adopted by the vanilla story formats, so it's not a SugarCube exclusive anymore)

    <<set $tm to random(10, 30)>>\
    <<print "<<start_timer " + $tm + ">>">>
  • Okay...Firstly, criticism has been noted and I'll learn.

    Secondly, thank you so much TheMadExile and EcnelOvelam...Your solution has done the trick and works fine.

    For the record I am using Sugarcube ver 0.9.9
  • I have nought to contribute except to point out that I did not actually write "Timer Test.tws", which is, as noted, by Astrid Bin and Stefano Russo, and which I was simply re-hosting on that page because the original website is dead.
Sign In or Register to comment.