Trouble with Chapel's Cycle Macro in Sugarcube 2.31.1

Okay so I am an art\GAME student. and I am SUPER NEW to coding.
Right now I’m using Chapel’s custom Cycle Macro to have a ‘time’ system and a ‘days’ system, because in my game, I want there to be certain events that only happen say…night time on a tuesday.
And Im having trouble getting an If statement to work, because the macro involves strings.

The code looks like this

   <<newcycle 'time' 3 1>>
   		<<phase 'Early Morning''Morning''Late Morning'>>
		<<phase 'Noon''Afternoon''Early Evening'>>
		<<phase 'Evening''Late Evening''Night'>>
	<</newcycle>>>
<<newcycle 'days' 27 1>>
    <<phase 'Sunday' 'Monday'>>
    <<phase 'Tuesday' 'Wednesday'>>
    <<phase 'Thursday' 'Friday' 'Saturday'>>
    <</newcycle>>

So I guess my real question is: How would I get it to understand “if its Afternoon on Monday, then this happens”

Would it be better just to switch to a more variable based cycle system???

Once again. super new. Thanks!

1 Like

So, I’m not very familiar with most of @Chapel 's custom macro’s, so I’ll let them (or someone more familiar than me) field this question.

However, I will suggest you use the </> button in the editor to format your code. Right now the forum is eating your tags and making really difficult to read your code. That button will prevent that.

Thanks for the advice! What exactly should I do? Im sorry idk where to apply the </>

It looks like you’ve got the idea. Just do it for all of your code instead of just the first portion. :slight_smile:

I don’t know what I did to fix the first portion unfortunately. Im real bad at this

Oh. Haha.

Just highlight the parts that you want to format and then click the </> button in the toolbar while it’s highlighted.

1 Like

Thank you for that help hahaha now I know how to post stuff at least.

1 Like

Try:

<<if Cycle.get('time').current() is 'Afternoon' and Cycle.get('days').current() is 'Monday'>>
    It is Monday afternoon.
<</if>>
3 Likes

As far as I can tell that worked perfectly!!! Thank you so so much!
I’m making like…a text based Detective RPG. So that mechanic was important… thank you so much!

1 Like

I might create a method, maybe cycle#check(phase), to make this easier and faster.

1 Like

@Chapel the man himself! Thank you for your very helpful macros good sir!
I’m just very inexperienced haha
How might I learn to create a method

As the developer of these libraries it’s really my job to add methods. You can do it, but it’s not really for beginners. Since you asked though, you’d do something like:

Object.assign(window.Cycle.prototype, {
    myNewInstanceMethod : function () {
        // code
    }
});

Object.assign(window.Cycle, {
    myNewStaticMethod : function () {
        // code
    }
});

Again though, that’s probably more advanced than you need to worry about right now. At any rate, I’ve added new methods to make this easier.

<<if Cycle.check('time', 'Afternoon') and Cycle.check('days', 'Monday')>>
  It's Monday afternoon!
<</if>>

Docs:
https://twinelab.net/custom-macros-for-sugarcube-2/#/cycles-system?id=method-cycleget
https://twinelab.net/custom-macros-for-sugarcube-2/#/cycles-system?id=method-instance-cyclecheck

You can use the Cycle.get('time').current() is 'Afternoon' way still if you want. You will need to install the new version of the cycle system macros to use the new methods.

2 Likes

@Chapel Thank you so so much for your help! I also use your inventory macro btw. You’re really good at making user-friendly content.

@Chapel So would I put that top code into my Javascript in Twine? to make Cycle.check a function

@Chapel or anyone else that knows
So I am using the Dialogue Box Macro, and everything has worked. but when I run this:

<<if $hugo.localtrustscore gte 2>>\
<<say 'Hemsly the Coachman' 'C:/Users/jarri/Downloads/coachman.jpg'>>\
Quite sorry sir! We are almost to Vicoria. Not much Longer now.
<</say>>

<<elseif $hugo.localtrustcore lt 0>>
  <<say 'Theodore Hemsly' 'C:/Users/jarri/Downloads/coachman.jpg'>>\
Whoops...sorry about that. I'd gather your things and hang on. Vicoria's close. But it's a bumpy ride til' then. 
<</say>>

<<elseif $hugo.localturstscore is 0>>
<<say 'Hemsly the Coachman' 'C:/Users/jarri/Downloads/coachman.jpg'>>\
Quite sorry sir! We are almost to Vicoria. Not much Longer now.
<</say>>
<</if>>

The dialogue box and picture only load for the first <> statement.
otherwise, the others still load, but not the dialouge box or anything in it. I dont get an error message or anything.

Also sorry for doign this on a reply, It wont let me make new messsages or posts for 4 more hours.

Thanks!

For putting code inline <like this>, you use a back tick.

Example: `<like this>`

And to solve your problem, you somehow managed to misspell localtrustscore in both of your elseif statements. :smile: I bet it’ll work if you spell them correctly.

1 Like

Additionally, even once you fix the spelling, nothing will happen if $hugo.localtrustscore is greater than 0 and less than 2. I’m not sure if you wanted nothing to happen if, for example, $hugo.localtrustscore was set to 1.

You might want to just replace <<elseif $hugo.localturstscore is 0>> with <<else>> so that all of your bases are covered.

2 Likes

Oh wow! I literally didn’t notice I mispelled ‘score’ in the variables. Thats embaressing!!! Thanks guys, Sorry haha