ADRIFT Forum


The place to discuss the ADRIFT Interactive Fiction toolkit

Problem with Accessing Arrays inside a Loop

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.

Problem with Accessing Arrays inside a Loop

Postby elfindor » Sat Mar 18, 2017 5:44 am

It's been a while since I've been able to really sit down and enjoy using ADRIFT and with all the new features of 5.0 It's been a new adventure all over again.

One of the really cool features I've discovered is being able to use a loop to set data for an array. However, I seem to have hit a road block with something that seems logical but just isn't working.

Scenario: I have several "suspects" in my game and that all have a set of eleven attributes. So I have set each of these attributes as an array and am using a loop to add data to each them as an action in a setup task.

So, this works:
adrift Code: Select all
FOR %Loop% = 1 to 7:
SET susGender[%Loop%] = EITHER("female","male"):
NEXT %Loop%


Next, I want to choose a random first name based on each gender. So, I set this action:
adrift Code: Select all
FOR %Loop% = 1 to 7:
SET susName[%Loop%] = IF(%susGender[%Loop]%="female",%femaleNames[RAND(1,30)]%,%maleNames[RAND(1,30)]%):
NEXT %Loop%


When I run this code I either get a hung Runner or sometimes I would get this message:

BAD EXPRESSION: If (susGender[1]="female","Cheryl","Peter")

I've checked syntax structure for IF expressions and ensured that the arrays have initial data so they are correct. From the above message, I'm assuming that I have the syntax correct, so am I missing something?

:x Elfindor
elfindor
 
Posts: 2
Joined: Wed Dec 21, 2011 1:25 am
Location: Melbourne, Australia

Re: Problem with Accessing Arrays inside a Loop

Postby ralphmerridew » Sun Mar 19, 2017 1:48 pm

Try changing
adrift Code: Select all
%susGender[%Loop]%="female"

to
adrift Code: Select all
%susGender[%Loop%]%="female"


(add percent after %Loop)
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: 2489
Joined: Fri Dec 13, 2002 11:56 pm
Location: Missouri

Re: Problem with Accessing Arrays inside a Loop

Postby elfindor » Thu Mar 30, 2017 12:25 am

Thanks, I can't believe that I missed that typo ... maybe I need to revisit the optometrist!
elfindor
 
Posts: 2
Joined: Wed Dec 21, 2011 1:25 am
Location: Melbourne, Australia


Return to ADRIFT 5.0

Who is online

Users browsing this forum: No registered users and 3 guests

cron