intfiction.org

The Interactive Fiction Community Forum
It is currently Sun Nov 18, 2018 2:33 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri May 11, 2018 8:05 am 
Offline

Joined: Fri May 11, 2018 7:40 am
Posts: 2
hello I am working with Sugarcube 2 in twine and I've got a large if statement that needs sorting as i have tried several different ways to do it.
I have tried to do each statement separate and it does work to an extent but it does not work out the way i want it to.
Therefore it needs to be one full statement.
Currently i am having issues where it can't find parent macro.

p.s Intellect value will keep changing as the game progresses.

here is part of the code:
<<if $Intellect lt 19>><<set $IntStatus to "Something">>
<<elseif not $Intellect lt 19>>
<<if $Intellect lt 29 gte 20>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 29 gte 20>>
<<if $Intellect lt 39 gte 30>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 39 gte 30>>
<<if $Intellect lt 49 gte 40>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 49 gte 40>>
<<if $Intellect lt 59 gte 50>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 59 gte 50>>
<<if $Intellect lt 69 gte 60>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 69 gte 60>>
<<if $Intellect lt 79 gte 70>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 79 gte 70>>
<<if $Intellect lt 79 gte 80>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 89 gte 80>>
<<if $Intellect lt 99 gte 90>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 99 gte 90>>
<<if $Intellect lt 109 gte 100>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 109 gte 100>>
<<if $Intellect lt 119 gte 110>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 119 gte 110>>
<<if $Intellect lt 129 gte 120>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 129 gte 120>>
<<if $Intellect lt 139 gte 130>><<set $IntStatus to "SomethingDifferent">>
<<elseif not $Intellect lt 139 gte 130>>
<<if $Intellect gte 140>><<set $IntStatus to "SomethingDifferent">>
<</if>>
$IntStatus

Thanks in advance
Creativemrgamer


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat May 12, 2018 2:20 am 
Offline
User avatar

Joined: Tue Nov 08, 2011 8:11 am
Posts: 2757
Location: US - Central
Using "else" should be exclusionary in most boolean logic. If I say "if the fruit is the orange, A; else, B" means that B can't happen if the fruit is the orange.

I'm no Twine-Sugarcube expert, but it seems though you should be able to say theoretically:

Code:
if A = 1: then foo;
elseif A = 2: then bar;
endif

You shouldn't need to specify

Code:
if A = 1 and A <> 2: then foo;
elseif A = 2 and A <> 1: then bar;
endif.

Because if A = 1, it can't also hold that A = 2, which seems to be an overcomplication in your code which could be simplified thusly:

Code:
<<if $Intellect lte 19>>
  <<set $IntStatus to "0-19">>
<<elseif $Intellect gte 20 and $intellect lte 29>>
  <<set $IntStatus to "20-29">>
<<elseif $Intellect gte 30 and $intellect lte 39>>
  <<set $IntStatus to "30-39">>
<<elseif $intellect gte 40 and $intellect lte 49>>
  <<set $IntStatus to "40-49">>
[...]


:shock:

_________________
http://hanonondricek.wixsite.com/pyramidif
https://pyramidif.itch.io/


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun May 13, 2018 7:22 pm 
Offline

Joined: Sat Dec 22, 2007 9:44 pm
Posts: 260
Couldn't you simplify that to:

Code:
<<if $Intellect lte 19>>
  <<set $IntStatus to "0-19">>
<<elseif $intellect lte 29>>
  <<set $IntStatus to "20-29">>
<<elseif $intellect lte 39>>
  <<set $IntStatus to "30-39">>
<<elseif $intellect lte 49>>
  <<set $IntStatus to "40-49">>
[...]


Top
 Profile Send private message  
Reply with quote  
PostPosted: Mon May 14, 2018 8:36 am 
Offline
User avatar

Joined: Tue Nov 08, 2011 8:11 am
Posts: 2757
Location: US - Central
I believe so. When you do a huge stack of if statements finding something in a range you have to be careful not to overlap your ranges. I was trying to make the range values clear as possible, but yes; so long as you include elseif statements after the first one it should work as the else implies exclusivity and negates all the others once a truth is registered.

I had inferred the OP had run into this kind of problem before with a bunch of separate if-endif lines and "lt X" operands that overlapped and that's why they were being so specific about meticulously coding opposing if and not-if statements.

_________________
http://hanonondricek.wixsite.com/pyramidif
https://pyramidif.itch.io/


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat May 19, 2018 2:19 pm 
Offline

Joined: Fri May 11, 2018 7:40 am
Posts: 2
Thanks for all the support and that seemed to fix the problem, I was originally shown to do this as so each section was in its own separate if statement.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sun Aug 12, 2018 8:36 pm 
Offline
User avatar

Joined: Sun Aug 12, 2018 8:11 pm
Posts: 1
I know it's a bit late, but a much shorter way of doing that would be this:
Code:
<<set _result = Math.trunc($IntStatus / 10).clamp(1, 14) - 1>>
<<set $IntStatus = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N"][_result]>>
$IntStatus

The first line sets the temporary variable "_result" to a value of 0 to 13, and the second line puts the value that of that item from the array into $IntStatus.

That way we go from 30 lines of code down to 3. :D


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group