I am trying to simulate a low level version of Quartiles. The PC pushes a button that has either 2 or 3 letter combinations assigned to it. Each time a button is pushed, the letters are added to a list to spell a word. The word needs to be checked against a list of words that are potion names.
I have a “macro/function?” that will add the letters to the list but I am not able to output the resulting list afterwards. And I think my list keeps getting reset to an empty list on each push of the button.
In other words, I have no idea how to make this work. Any help is appreciated.
This is an example of a button and the “macro/function?” that does not work.
potionWord(x)
{
//local words = ['MESMERIZE', 'ME', 'TEMPEST', 'STORM', 'GLACIAL', 'BLAST'];
local guess = [];
for(local i = 0; i <= guess.length; i++)
guess.push(x);
"you added <<x>> to the list. ";
}
tileTE: Button 'TE; crystal colorful letters tile;some' @panel
"The tile has the letters T and E engraved on it. "
makePushed()
{
"The letters appear on the transparent section above. ";
potionWord('TE');
}
collectiveGroups = [tiles]
;
What language are you using? You can add a return statement or similar to your potionWord function. The list is resetting because you’re initializing local guess to an empty list each time you push the button, if I’m interpreting the code correctly (I don’t know this language).
Thank you. I don’t know how I managed to post it without selecting the language. I have edited it. This is in TADS, ADV3Lite. I have tried with a return statement but it won’t compile.
Total stab in the dark.
I apologize that I am not familiar with adv3lite - I work in adv3. I think @Hidnook is on the right track though. From the code snippet above, I don’t see any functions that capture and track the current button sequence (perhaps an object that maps to the transparent section above)? Forgive the adv3 syntax, I think you would want to make potionWord a method of such an object, and have a property that stores/displays the in-progress guess:
clearSection : Readable, Component 'transparent section' 'transparent section'
"A readout of some kind. <<readDesc()>>. "
readDesc = "<<if curGuess == ''>>It is currently blank.
<<else>>It currently displays <<curGuess>>. "
curGuess = '' // current guess in progress
potionWord(x) {
local words = ['MESMERIZE', 'ME', 'TEMPEST', 'STORM', 'GLACIAL', 'BLAST'];
curGuess += x; // increment current guess
"You added <<x>> to the list, and the display now reads <<curGuess>>. ";
// test to see if current guess matches anything
local matchSpell = words.indexOf(curGuess);
if (matchSpell != nil) {
castSpell(curGuess);
} else {
"The spell appears incomplete. ";
}
// would want some algo that flags when guess needs reset here
}
;
Just off the cuff, would need translated to lite. Hope that helps!
if you work in adv3… I’m betting that you’re waiting impatiently the first of april, and then doing your “scientific research” at source level ! of course I’m REALLY curious & interested in the results of the research !
sorry for the brief OT, and
Best regards from Italy,
dott. Piergiorgio.
This won’t compile. The error has to do with the line curGuess = ''. The error reported is: expected property name in object definition, but found "="
clearSection : Component 'transparent section' @panel
"A readout of some kind. <<readDesc()>>. "
readDesc = "<<if curGuess == ''>>It is currently blank.
<<else>>It currently displays <<curGuess>>. "
;
curGuess = '' // <-THIS WON'T COMPILE
potionWord(x) {
local words = ['MESMERIZE', 'ME', 'TEMPEST', 'STORM', 'GLACIAL', 'BLAST'];
curGuess += x; // increment current guess
"You added <<x>> to the list, and the display now reads <<curGuess>>. ";
// test to see if current guess matches anything
local matchSpell = words.indexOf(curGuess);
if (matchSpell != nil) {
castSpell(curGuess);
} else {
"The spell appears incomplete. ";
}
// would want some also that flags when guess needs reset here
}
;
I finally had some time to try this again. The only output I get after pushing a button is:
The letters appear on the transparent section above. <<curGuess>>is empty or at least does not output anything.
clearSection : Component 'transparent section' @panel
"A readout of some kind. <<readDesc()>>. "
readDesc = "<<if curGuess == ''>>It is currently blank.
<<else>>It currently displays <<curGuess>>. "
curGuess = ''
castSpell(x) {
local words = ['MESMERIZE', 'ME', 'TEMPEST', 'STORM', 'GLACIAL', 'BLAST'];
curGuess += x; // increment current guess
"You added <<x>> to the list, and the display now reads <<curGuess>>. ";
// test to see if current guess matches anything
local matchSpell = words.indexOf(curGuess);
if (matchSpell != nil) {
castSpell(curGuess);
} else {
"The spell appears incomplete. ";
}
// would want some also that flags when guess needs reset here
}
;
tileTE: Button 'TE; crystal colorful letters tile;some' @panel
"The tile has the letters T and E engraved on it. "
isListed = nil
makePushed()
{
"The letters appear on the transparent section above. <<curGuess>> ";
castSpell('TE');
}
collectiveGroups = [tiles]
;
I think you need to reverse the order of the statements in you makePushed() method, since currently that method is displaying the value of curGuess before castSpell() has updated it.
Also your makePushed() method needs to call reference curGuess and castSpell() on the cleatSection object, i.e.,
tileTE: Button 'TE; crystal colorful letters tile;some' @panel
"The tile has the letters T and E engraved on it. "
isListed = nil
makePushed()
{
clearSection.castSpell('TE');
"The letters appear on the transparent section above.
<<clearSection.curGuess>> ";
}
collectiveGroups = [tiles]
;
Thank you again all who helped. The final solution is below. The words can all be spelled with 3 button pushes, so I counted to pushes and reset the display after 3 pushes and no word match.
//the tiles can be pushed and are then put in order in the upper screen, spelling a potion
clearSection : Component 'transparent section' @panel
"A readout of some kind. <<readDesc()>>. "
countPushes = 0
curGuess = ''
castSpell(x) {
local words = ['TRANCE', 'TEMPEST', 'GLACIER'];
countPushes += 1; // increment number of pushes
curGuess += x; // increment current guess
local matchSpell = words.indexOf(curGuess);
if (matchSpell != nil) {
"A click is heard and the cabinet doors open to reveal a single vial of potion. ";
potionCabinet.isLocked = nil;
potionCabinet.isOpen = true;
}else if(matchSpell == nil && countPushes ==3) {
"The display blinks then clears. Looks like you have to start over. ";
curGuess = '';
countPushes = 0;
}else{
"The display now reads <<curGuess>>. ";
}
}
;
tileTE: Button 'TE; crystal colorful letters tile;some' @panel
"The tile has the letters T and E engraved on it. "
isListed = nil
makePushed()
{
clearSection.castSpell('TE');
"<<clearSection.curGuess>> ";
}
collectiveGroups = [tiles]
;
//MORE BUTTONS BELOW