HTML Twine/sucarcube error

Marduk73

New Member
Jul 19, 2021
12
2
Hi there, I'm trying to build a time/date system consisting of dayparts, weekdays, weeks and seasons
In my StoryInit :
Code:
<<set setup.dayPart = ["Morning", "Late Morning", "Noon","Afternoon", "Evening", "Late Evening", "Late Night","Night"]>>
<<set $gameTime = 0>>
<<set setup.weekPart = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
<<set $gameWeekDay = 0>>
<<set setup.week = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]
<<set $gameWeek = 0>>
<<set setup.season = ["Summer", "Autumn", "Winter", "Spring"]
<<set $gameSeason = 0>>
In my StoryCaption:
Code:
<<=setup.dayPart[$gametime]>>
<<=setup.weekPart[$gameWeekDay]>>
<<=setup.week[$gameWeek]>>
<<=setup.season[$gameSeason]>>
and as widget:
Code:
<<widget "TimeModus">>
   <<if ++$gameTime >= setup.dayTimes.length>>
       <<set
                $gameTime = 0,
                $gameWeekDay.setDate($gameWeekDay.getDate() +1)
             <<if ++$gameWeekDay >= setup.weekPart.length>>
    <<set
             $gameWeekDay =0,
             $gameWeek.setDate($gameWeek.getDate() +1)
             <<if ++$gameWeek >= setup.week.length>>
    <<set  
             $gameWeek = 0,
             §gameSeason.setDate($gameSeason.getDate() +1)
             <<if ++$gameSeason >= setup.season.length>>
    <<set
             $gameSeason =0,
                            >>
                        >>
                    >>
                >>
                            <</if>>
                        <</if>>
                    <</if>>
                <</if>>
</widget>>
this give my the error:
error.PNG
Where is my mistake?
 
Last edited:

guest1492

Member
Apr 28, 2018
312
262
You are missing a lot of closing brackets (>>) in your StoryInit passage. You left them out when defining setup.weekPart, setup.week, and setup.season.

Your widget is also filled with errors. I'm not sure how familiar you are with JavaScript or programming in general. As shown in your StoryInit, $gameWeekDay, $gameWeek, and $gameSeason are variables of the Number type/class. does not have methods setDate() or getDate().

You can think of macros in SugarCube as functions that don't return anything. Some macros have multiple tags (eg <<if>><<elseif>><<else>><</if>>) whereas others only have a single tag (eg <<set>>).

Calling a macro is done like so: <<link arguments>>content<</link>>. The arguments can be variables, values, expressions, or function calls but they cannot be calls to other macros. The content can contain other macro calls. (Content is basically just another argument that's passed as a string and then parsed.)

The <<set>> macro only has a single tag so you cannot call other macros.

There are probably a lot more errors shown if you would open your browser console.
 
  • Like
Reactions: Marduk73

Marduk73

New Member
Jul 19, 2021
12
2
Ok, the brackets are set, now show on StoryCaption correct, the widget is crap, right?
Code:
<<widget "passTime">>

        <<set $gameTime++>>
        <<if $gameTime >= $dayTime.length>>
          <<set
                $gameTime = 0,
                $gameDay ++,
           >>
    <<set $gameWeekDay = $gameDay%7 >>
  
   <</if>>
  
<</widget>>
but this is correct, and is working.
But I still need weeks and seasons in addition
Where or how do I insert the code?
 

Marduk73

New Member
Jul 19, 2021
12
2
I tried to expand the last widget, could it work like that? if not what do i need to change where? Please help me
Code:
<<widget "passtime">>
   <<set $gameTime++>>
   <<if $gameTime >= setup.dayPart.length>>
       <<set $gameTime = 0,$gameDay++ >>
        <<if $gameDay <= setup.weekPart.length>>
            <<set $gameDay++ >>
            <<else>
            <<set $gameDay = 0, $gameWeek++>>
                <<if $gameWeek <= setup.week.length>>
                    <<set $gameWeek++>>
                    <<else>>
                    <<set $gameWeek = 0, $gameSeason++>>
                        <<if $gameSeason <= setup.season.length>>
                            <<set $gameSeason++>>
                            <<else>>
                            <<set $gameSeason = 0, $gameYear++>>
                                <<if $gameYear <= setup.years.length>>
                                    <<set $gameYears++>>
                                <</if>
                        <</if>>
                <</if>>
        <</if>>
    <<set $gameWeekDay  = $gameDay%7 >>
    <<set $gameWeeks     = $gameWeek%13>>
    <<set $gameSeasons  = $gameSeason%4>>
    <<set $gameYear     = $gameYears%10>>
   <</if>>   
<</widget>>
 

guest1492

Member
Apr 28, 2018
312
262
Your syntax is correct but your code is wrong (as in it's illogical and doesn't do what you want). Your first or outermost conditional is correct. You should have kept the same pattern. There's also no need for all the modulo operations at the end (especially for $gameYear).

I'm not sure if you're making typos or you have new variables. You have $gameWeek and $gameWeeks, $gameSeason and $gameSeasons, etc.
 
Last edited:
  • Like
Reactions: Marduk73

Marduk73

New Member
Jul 19, 2021
12
2
Thx, the code works partitionaly, it´s increased 2 not 1, the fault was easy to find, now the code is:
Code:
<<widget "passtime">>
   <<set $gameTime++>>
   <<if $gameTime >= setup.dayPart.length>>
       <<set $gameTime = 0,$gameDay++ >>
        <<if $gameDay >= setup.weekPart.length>>
            <<set $gameDay = 0, $gameWeek++>>
                <<if $gameWeek >= setup.week.length>>
                    <<set $gameWeek = 0, $gameSeason++>>
                        <<if $gameSeason >= setup.season.length>>
                            <<set $gameSeason = 0, $gameYear++>>
                                <<if $gameYear >= setup.years.length>>
                                    <<set $gameYears = 0>>
                                <</if>>
                        <</if>>
                <</if>>
        <</if>>
  <</if>>   
<</widget>>
 
  • Like
Reactions: guest1492