0 votes
by (470 points)
edited by

Hello guys. All this day i trying to create macro. His function is adding word endings for russian language. My code:
 

<<set $ass_titles to ["жоп", "задниц"]>>

<<set $ass_size_1_titles to ["маленьк", "тощ",]>>
........
<<widget "ass_aya">>\
    <<if $ass_size is 1>>\
        <<if $ass_size_1_titles is "маленьк">>\
            either($ass_size_1_titles)ая\
            either($ass_titles)а\
        <<elseif $ass_size_1_titles is "тощ">>\
            either($ass_size_1_titles)оя\
            either($ass_titles)а\
        <</if>>\
    ..................
    <</if>>\
<</widget>>\
............
<<click [[Маленькая|Character Creation]]>><<set $ass_size to 1>><</click>>



But string in code:
 

either($ass_size_1_titles)ая\ 
...
either($ass_titles)а\



 in game looks like:
 

...Твоя either(маленьк, тощ)ая either(жоп, задниц)а приятно...



while it should look like:

"Твоя маленькая/тощая жопа/задница..."

What im doing wrong? Thanks in advance

1 Answer

0 votes
by (68.6k points)

You need to use the <<print>> macro to output the results of your either() function calls.

Your second <<if>> has a improper conditional, the logical-OR operator joins sub-expressions, so you must provide complete expressions on both sides.  That said, you're attempting to check the contents of an array there and in the following <<elseif>>, which you do with one of the includes family of array methods—i.e. <Array>.includes(), <Array>.includesAll(), <Array>.includesAny()—rather than with any of the standard equality or relation operators.  In this case, you probably want <Array>.includesAny() for the <<if>> and simply <Array>.includes() for the <<elseif>>.

For example:

<<widget "ass_aya">>\
    <<if $ass_size is 1>>\
        <<if $ass_size_1_titles.includesAny("маленьк", "тощ")>>\
            <<print either($ass_size_1_titles)>>ая\
            <<print either($ass_titles)>>а\
        <<elseif $ass_size_1_titles.includes("ужат")>>\
            <<print either($ass_size_1_titles)>>оя\
            <<print either($ass_titles)>>а\
        <</if>>\
    ..................
    <</if>>\
<</widget>>

Additionally.  If the $ass_size_1_titles array isn't going to change, you could actually use an <<else>> in place of the <<elseif>>, since if the <<if>> was not true then the <<elseif>>'s conditional will always be true.  In other words, with the $ass_size_1_titles array as-is, you could probably get away with the following:

        <<if $ass_size_1_titles.includesAny("маленьк", "тощ")>>\
            <<print either($ass_size_1_titles)>>ая\
            <<print either($ass_titles)>>а\
        <<else>>\
            <<print either($ass_size_1_titles)>>оя\
            <<print either($ass_titles)>>а\
        <</if>>\

PS: In the future, please use the code snippet widget—it's the first item on the editor bar—when posting code or markup.

by (470 points)
edited by
I use the code you said and get this

...Твоя Error: <<ass_aya>>: error within widget contents (Error: <<if>>: bad conditional expression in <<if>> clause: Unexpected string) приятно...
by (68.6k points)
Mea culpa.  I got hung up on the improper conditional and completely zoned out on the fact that you're checking array membership.  I've corrected my answer.
by (470 points)
edited by
It works! You amazing! thank you so much
by (68.6k points)
Where are you defining $ass_size_1_titles?  It must be defined before you can use it within the widget.
by (470 points)
edited by
yes, i just miss this string and hurried to answer. Now it works and i am very grateful to you. Thanks for help <3
by (470 points)
edited by

im sorry what im asking you help again. Without a doubt, youre code help me, but the widget still working wrong. As i use sugarcube1, i change "includes" for "contains" and have this code: 

<<set $ass_titles to ["поп"]>>

<<widget "ass_a">>\
	<<if $ass_size eq 1>>\	
		<<if $ass_size_1_titles.containsAny("маленьк", "тощ")>>\
			<<print either($ass_size_1_titles)>>ая\
			<<print either($ass_titles)>>а\
		<<elseif $ass_size_1_titles.containsAny("ужат")>>\
			<<print either($ass_size_1_titles)>>оя\
			<<print either($ass_titles)>>а\
		<</if>>\
	..................
	<</if>>
<</widget>>

If widget chose the "ужат" ending still stay "ая" instead "оя".

...Твоя маленькая попа приятно...

...Твоя тощая попа приятно...

...Твоя ужатая(it should be "ужатоя") попа приятно...

the same happens if <<elseif>> is empty, as are you say

by (68.6k points)

[…] As i use sugarcube1, i change "includes" for "contains" […]

Ah.  That's a good reason to specify the version of SugarCube in the future.  SugarCube v1 has been deprecated for a while now and only receives critical bug fixes, so I'm going to assume SugarCube v2 when someone simply says or tags "SugarCube".


Anyway.  The code looks correct, so I'm going to guess that you're having an encoding problem.  If you copy/pasted code from here back into your project, it's possible that the encodings within that code are different from your original code.  In other words, some of your Russian strings may be encoded in your local code page while others are encoded in UTF-8.  If that's the case, then the strings will never match, even though they encode the same words.  Try retyping the Russian strings within the widget and the arrays.  Hopefully, that will resolve the issue.

by (470 points)
edited by

sorry about version. My mistake. But if i change platform to SugarCube2, i have same trouble. And the same trouble happen with english symbols. I triyng to combine english/russian words, sugarcube1/sugarcube2, but if <<if>> has anything related arrays (.includes, .contains), widget dont work right. Usually work only first string.

For example (new clear story on SugarCube2 with 3 passages):

StoryInit:

<<set $changes to []>>

PASSAGE 0:

<<click [[DSA|passage0]]>>
	<<set $changes.push("1")>>
<</click>>

<<click [[ASD|passage0]]>>
	<<set $changes.push("2")>>
<</click>>

[[s]]

PASSAGE S:

$changes

<<if $changes.contains("1")>>
	description1
<<elseif $changes.contains("2")>>
	description2
<</if>>

result: 

1, 2


description1

Looks strange

by (68.6k points)

But if i change platform to SugarCube2, i have same trouble.

If it's an encoding problem, as I suggested previously, it won't matter what version of SugarCube you use, because you still need to correct the encoding issue.  If it's not, then we're likely having a miscommunication somewhere.

As for your example.  The result you're seeing is exactly what you should, based on the output of $changes.  Your result shows that $changes contained both "1" and "2", meaning that you clicked on both links in passage0.  With the way you have your logic set up in passage s, it will only print description1 as long as it contains "1"—the <<elseif …>> will only be tested if the <<if>> fails, which it won't as long as "1" exists within the array.  The only way description2 will print is if "1" doesn't exist within the array or you change the logic to something like the following, where each condition you're testing for is within separate <<if>> macros:

<<if $changes.contains("1")>>
	description1
<</if>>
<<if $changes.contains("2")>>
	description2
<</if>>

 

by (470 points)
ok. I will look for other ways. Thanks for answer!
...