ADRIFT Forum


The place to discuss the ADRIFT Interactive Fiction toolkit

Multiple expressions within Text Boxes

This forum is the place to learn about and discuss ADRIFT 5. Feel free to mention any bugs you find here, but please also add these to the Bugs & Enhancements list.

Please also refer to the ADRIFT 5 Wiki for more information.

Multiple expressions within Text Boxes

Postby Minerva » Thu Aug 09, 2012 11:32 pm

Hiya everyone,

I'm relatively new but rather ambitious with the ADRIFT engine, and I've been trying to create a system for generating dynamics descriptions for the player character within my game. I've determined that I should use expressions within the description text box to accomplish this, and I've managed to work around a few of the problems I've had... but they certainly feel like workarounds rather than elegant solutions.

Basically, I've been working with something a bit like this:
adrift Code: Select all
 
<# if(%hair_score%=0,"%hair_array[RAND(1,2)]%","") #>
 


...Which works great! The first variable (hair_score) is used within the game itself, and the array (hair_array) picks one of the descriptions for that specific type of hair when the user calls the character's description. However, the moment I introduce another expression into the description, it only seems to care about the last one; so...

adrift Code: Select all
 
<# if(%hair_score%=0,"%hair_array[RAND(1,2)]%","") #>
<# if(%hair_score%=1,"%hair_array[RAND(3,4)]%","") #>
 


...only seems to return anything the first variable (hair_score) is equal to one. Even more confusing is that when the variable is equal to one, it seems to return the array result twice! I'm guessing that's because the second command overrides the first, which is a bit concerning considering this is just one element in the system I'm trying to implement. If I'm to actually use this in practice, I'm going to need to be able to define several other attributes. I suppose if the variables were different, it wouldn't override?...

Anyway, the workaround I found for this particular instance was the following:

adrift Code: Select all
 
<# if(%hair_score%=0,"%hair_array[RAND(1,2)]%","") & if(%hair_score%=1,"%hair_array[RAND(3,4)]%","") #>
 


This seems to work properly, but doesn't look at all elegant or organized when I'm actually working with the expressions. Trying to format it in a different way seems to screw with how the expression is being read. So basically, I'm wondering if there is a more clean and elegant-looking solution to my problem.

Thanks for reading!
Minerva
 
Posts: 6
Joined: Thu Aug 09, 2012 11:16 pm

Re: Multiple expressions within Text Boxes

Postby Campbell » Fri Aug 10, 2012 8:13 am

Are you running 5.0.24? This should have been fixed in the last release (issue 18484).
ADRIFT Developer developer.
User avatar
Campbell
Site Admin
 
Posts: 3852
Joined: Sun Jun 23, 2002 11:05 am
Location: Edinburgh, Scotland

Re: Multiple expressions within Text Boxes

Postby Minerva » Fri Aug 10, 2012 8:17 am

Ah, no! I'm running 5.0.23! I'll try that now!~

EDIT:
Okay. I've run some pretty quick tests, and it seems that it basically allows several instances of the same variable now, which is good... but it's still not quite suited for what I was hoping to do.

This technically works properly now, but it inserts any extra lines for every line between qualifying statements and false statements:
adrift Code: Select all
 
<# if(%hair_score%=0,"%hair_array[RAND(1,2)]%","") #>
<# if(%hair_score%=1,"%hair_array[RAND(3,4)]%","") #>
 


It basically means that while it's valid, you can't have cleanliness on both the game-side and the code-side; you can't have your cake and eat it, too. I tried the following alternative in order to remove the extra game-side lines, but it wasn't valid:
adrift Code: Select all
 
<#
if(%hair_score%=0,"%hair_array[RAND(1,2)]%","")
if(%hair_score%=1,"%hair_array[RAND(3,4)]%","")
#>
 

 
In order to get the proper reading on the game-side, I had to set all my code side-by-side like so:
adrift Code: Select all
 
<# if(%hair_score%=0,"%hair_array[RAND(1,2)]%","") #><# if(%hair_score%=1,"%hair_array[RAND(3,4)]%","") #>
 


I suppose this normally wouldn't be a huge deal, but I'm trying to aim for a really great level of detail in terms of the character customization, and it's gotten rather demanding in terms of expressions, and it would be incredibly useful if there were some way to have the code read in a more orderly fashion. :[
Minerva
 
Posts: 6
Joined: Thu Aug 09, 2012 11:16 pm

Re: Multiple expressions within Text Boxes

Postby Minerva » Fri Aug 10, 2012 9:00 am

So I messed around and a little bit of ingenuity brought a bit of improvement:

While the code seems to care about linebreaks within the expression sections (the "<#" and "#>" nesting), it rightly doesn't care about linebreaks within note sections (the '<!--' and '-->' nesting). I've basically reformatted the code using this knowledge:
adrift Code: Select all
 
<!-- PC's Hair Section
-->
<# if(%hair_score%=0,"%hair_array[RAND(1,2)]%","") #><!--
-->
<# if(%hair_score%=1,"%hair_array[RAND(3,4)]%","") #><!--
-->
<# if(%hair_score%=2,"%hair_array[RAND(5,6)]%","") #><!--
-->
... ad infinitum~
 

...And it was valid!

I'd prefer not having to separate it with this workaround, but at least there's a way to do it. Pfft~
Minerva
 
Posts: 6
Joined: Thu Aug 09, 2012 11:16 pm

Re: Multiple expressions within Text Boxes

Postby ralphmerridew » Fri Aug 10, 2012 1:14 pm

Would something like:

<# "%hair_array[RAND(2*%hair_score%+1, 2*%hair_score%+2)]%" #>
work?


Alternately:
<# if(%hair_score%=0,"%hair_array[RAND(1,2)]%", if(%hair_score%=1, "%hair_array[RAND(3,4)]", if(%hair_score% = 2, "%hair_array[RAND(5,6)]%", "%hair_array[RAND(7,8)]"))) #>
(Extend last part as needed)
Bloodhounds can make you laugh and cuss in the same breath. They are endearing, faithful, and can sling drool ten feet in any direction. -- Virginia Lanier
User avatar
ralphmerridew
 
Posts: 2195
Joined: Fri Dec 13, 2002 11:56 pm
Location: Missouri

Re: Multiple expressions within Text Boxes

Postby ElliotM » Fri Aug 10, 2012 3:08 pm

You could use multiple alternate descriptions to separate out your code while maintaining readability and clean white space, though the con there would be that you wouldn't be able to view all of your code at once.

(If you didn't know, you can right click in just about any text box and choose add alternate description). Leave the restrictions blank and choose Append to Previous: As long as you don't put in any carriage returns by mistake, this should keep your output in the runner as one contiguous paragraph, if that's what you are aiming for. You can also rename alt description tabs by right clicking on them.
ElliotM
 
Posts: 507
Joined: Tue Apr 17, 2007 8:04 pm
Location: The Midwest in the USA

Re: Multiple expressions within Text Boxes

Postby Minerva » Sun Aug 12, 2012 1:53 am

@Ralph

I think that would work, but it's more counter to what I was hoping to do. Having code that extends out like that would probably just confuse me and make me more disorganized than anything else. XD

@Elliot

I was considering using alternative descriptions. It would make it cleaner, but less organized, I think. I might mess around with it a bit more, but I think my workaround is the best way to tackle it as far as my personal needs. I really do appreciate the idea, though... who knows! Maybe I can make it work better with a bit of tweaking...
Minerva
 
Posts: 6
Joined: Thu Aug 09, 2012 11:16 pm

Re: Multiple expressions within Text Boxes

Postby Campbell » Sun Aug 12, 2012 10:13 am

I suppose you could just have:
adrift Code: Select all
 <# %hair_array[RAND((2 * %hair_score%) + 1, (2 * %hair_score%) + 2)]% #>
ADRIFT Developer developer.
User avatar
Campbell
Site Admin
 
Posts: 3852
Joined: Sun Jun 23, 2002 11:05 am
Location: Edinburgh, Scotland

Re: Multiple expressions within Text Boxes

Postby Minerva » Mon Aug 13, 2012 9:48 pm

Campbell wrote:I suppose you could just have:
adrift Code: Select all
 <# %hair_array[RAND((2 * %hair_score%) + 1, (2 * %hair_score%) + 2)]% #>


This is a much more ingenious and simple piece of code which seems like it'd work for what I'm thinking of. If only my brain worked that way!

Thanks, Campbell! :Thanks:
Minerva
 
Posts: 6
Joined: Thu Aug 09, 2012 11:16 pm

Re: Multiple expressions within Text Boxes

Postby ralphmerridew » Mon Aug 13, 2012 11:22 pm

Campbell wrote:I suppose you could just have:
adrift Code: Select all
 <# %hair_array[RAND((2 * %hair_score%) + 1, (2 * %hair_score%) + 2)]% #>


Wasn't that my first suggestion?
Bloodhounds can make you laugh and cuss in the same breath. They are endearing, faithful, and can sling drool ten feet in any direction. -- Virginia Lanier
User avatar
ralphmerridew
 
Posts: 2195
Joined: Fri Dec 13, 2002 11:56 pm
Location: Missouri

Re: Multiple expressions within Text Boxes

Postby Campbell » Tue Aug 14, 2012 8:52 am

ralphmerridew wrote:Wasn't that my first suggestion?
So you did, sorry. Have to admit, I missed that.
ADRIFT Developer developer.
User avatar
Campbell
Site Admin
 
Posts: 3852
Joined: Sun Jun 23, 2002 11:05 am
Location: Edinburgh, Scotland

Re: Multiple expressions within Text Boxes

Postby Minerva » Fri Aug 17, 2012 8:19 am

Campbell wrote:
ralphmerridew wrote:Wasn't that my first suggestion?
So you did, sorry. Have to admit, I missed that.


As did I... That's strange! I only remember seeing the longer code. :|
Minerva
 
Posts: 6
Joined: Thu Aug 09, 2012 11:16 pm


Return to ADRIFT 5.0

Who is online

Users browsing this forum: No registered users and 1 guest