Howdy, Stranger!

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

Clocks still driving me nuts

2»

Comments

  • All names in SugarCube are case-sensitive. You've tagged the passage with Widget, not widget—they are not the same thing.

    Correct that problem and it should work.
  • Hum, ok noob spotted ^^.

    It's working.
    Thx a lot.

    It will teach me to put uppercase anywhere ...

    BTW : I wish you all : Happy New Year.
  • Well, not everything is in all lowercase. Just match the case given within the documentation and you'll be fine.

    Happy New Year to you too. :smiley:
  • edited January 2017
    Hi, back again,

    The widget is working fine.
    But I have a question : (OMG not him again !!!)
    Can we make something like that ?
    <<if ($Appointment==1 and <<date>> is "Thu Feb 2, 2017 09:00") or ($Appointment==2 and <<date>> is "Thu Feb 2, 2017 14:00")>><<set $Aappointment to true>><</if>>
    
    <<if $Aappointment is false>>Hi Sir, have we got an appointment?
    <<elseif $Aappointment>>Hello sir, you must be Marc?
    <</if>>
    

    In my game, I try to create an appointment at an hour the next day.
    Actually the date is : Wed Feb 1, 2017 08:00
    And i would like to put an appointment at : Thu Feb 2, 2017 09 (I'ld like not to put minutes to have flexibility).

    Thx for the answer.
  • Alianna wrote: »
    Can we make something like that ?
    <<if ($Appointment==1 and <<date>> is "Thu Feb 2, 2017 09:00") or ($Appointment==2 and <<date>> is "Thu Feb 2, 2017 14:00")>><<set $Aappointment to true>><</if>>
    
    <<if $Aappointment is false>>Hi Sir, have we got an appointment?
    <<elseif $Aappointment>>Hello sir, you must be Marc?
    <</if>>
    

    In my game, I try to create an appointment at an hour the next day.
    Actually the date is : Wed Feb 1, 2017 08:00
    And i would like to put an appointment at : Thu Feb 2, 2017 09 (I'ld like not to put minutes to have flexibility).
    Something like that may be done, yes, though it will require a bit of setup. Also, you cannot call a macro from inside the arguments of another macro, so you'll have to use $gameDate directly. You're also being redundant, as there's no reason to have two <<if>> invocations there.

    Try something like the following:
    <<silently>>
    	/* Date() params: year , month(0-based) , day , hour(24H) [, minute [, second ]] */
    
    	/* Set the 1st appointment date/time: Thu Feb 2, 2017 09:00 */
    	<<set _appointment1 to new Date(2017, 1, 2, 9)>>
    
    	/* Set the 2nd appointment date/time: Thu Feb 2, 2017 14:00 */
    	<<set _appointment2 to new Date(2017, 1, 2, 14)>>
    
    	/* Set the values we'll actually compare */
    	<<set _now to $gameDate.toDateString() + ' ' + $gameDategetHours()>>
    	<<set _appointment1 to _appointment1.toDateString() + ' ' + _appointment1.getHours()>>
    	<<set _appointment2 to _appointment2.toDateString() + ' ' + _appointment2.getHours()>>
    <</silently>>
    \<<if
    	($Appointment is 1 and _now is _appointment1) or
    	($Appointment is 2 and _now is _appointment2)
    >>
    \<<set $Appointment to true>>
    \Hello sir, you must be Marc?
    \<<else>>
    \Hi sir, have we got an appointment?
    \<</if>>
    
    I'm assuming that you're using the boolean value of $Appointment later. If you're only using it within the second <<if>> invocation, then you probably don't need that assignment at all.
  • edited January 2017
    Hi thx, it's working.
    I would love to understand javascript as you do.

    BTW :
    <<set _now to $gameDate.toDateString() + ' ' + $gameDate.getHours()>>
    

    There was a "." missing. for those who will copy it.
    I'm assuming that you're using the boolean value of $Appointment later. If you're only using it within the second <<if>> invocation, then you probably don't need that assignment at all.

    I don't know, so I prefere keep it for the moment.

    Thx again.
    Have a good day.
  • edited January 2017
    Hi,

    As I work a lot with date, I would like to extend the "appointment" script to something generic.

    I mean a script that take the actual game date, store it (the date continue to run in the game), add one day (for exemple), and check with "now" if that's the same.

    I try :
    put the code in the link.
    [[I will take the one at 9h.|Mayor Secretary Appointment][$Appointment to 1; _tomorrow to new Date($gameDate.getDate()+1); _tomorrow to _tomorrow.toDateString()]]
    

    Then call it in another passage.
    <<silently>>
    	/* Extract the value of the hour */
    	<<set _hour to $gameDate.getHours()>>
    	/* Values which will be compare */
    	<<set _now to $gameDate.toDateString()>>
    <</silently>>
    
    <<if $Appointment==0>>[[I would like to take an appointment with the Mayor please.|Mayor Secretary Appointment]]<</if>>
    	<<if 
    		($Appointment is 1 and _now is _tomorrow and _hour is 9) or
    		($Appointment is 2 and _now is _tomorrow and _hour is 14)
    >>
    <<set $Appointment to true>>blabla
    <<else>>blabla<</if>>
    

    There is no error, but nothing pop.

    Thx.
  • There are two issues with your setter link. You're assigning your tomorrow value to a temporary variable, which is only valid within the passage where it's set. You're passing a single integer value, the number of days, to the Date() constructor, which is not going to do what you want.

    The former is solved by using a story variable to hold the tomorrow value. The latter is solved by using the <Date>.setDate() method—I'd also suggest creating a function to handle the addition of days, since it gets a bit busy within your setter link otherwise.


    Add the following to your script section to set up the function: (Twine 2: goes in Story JavaScript; Twine 1: goes in script-tagged passage)
    /*
    	Takes a Date object, or compatible representation, and a number of days.
    	Returns a new Date object created from the given Date modified by the given
    	number of days.  Does not modify the original date.
    */
    window.addDaysToDate = function (origDate, days) {
    	var date = new Date(origDate);
    	date.setDate(date.getDate() + days);
    	return date;
    };
    


    You may then do the following within your setter link:
    [[I will take the one at 9h.|Mayor Secretary Appointment][$Appointment to 1; $tomorrow to addDaysToDate($gameDate, 1).toDateString()]]
    


    And the later passage:
    <<silently>>
    	/* Extract the value of the hour */
    	<<set _hour to $gameDate.getHours()>>
    
    	/* Values which will be compare */
    	<<set _now to $gameDate.toDateString()>>
    <</silently>>
    \<<if $Appointment is 0>>[[I would like to take an appointment with the Mayor please.|Mayor Secretary Appointment]]<</if>>
    <<if
    	($Appointment is 1 and _now is $tomorrow and _hour is 9) or
    	($Appointment is 2 and _now is $tomorrow and _hour is 14)
    >>
    \<<set $Appointment to true>>
    \…blabla…
    \<<else>>
    \…blabla…
    \<</if>>
    
    NOTE: Depending on how you intend for that to function, those two <<if>> macros should possibly be unified.
  • Hi,

    Thx It's working.
    Noted for the issues.

    Thx again.
Sign In or Register to comment.