Do/While Loops  SOLVED

User-to-User discussion about the PhraseExpress macro programming.
Post Reply
baffleblend
Posts: 4
Joined: 25 Oct 18, 23:33

Do/While Loops

Post by baffleblend » 16 Oct 19, 21:36

Hello. This is something I'm having some trouble figuring out. From what I'm seeing, PhraseExpress only supports macro loops that increment by counter like For Loops. Those are not the kind of loops I want to implement.

For example, something I want to do in one specific macro is generate a random number between 1 and 117. However, there are several values in that range that are invalid (6, 11, 19, 28, 29, 32, 33, 52, 64, 65, 99, 109, 115).

How do I make something loop not a fixed number of times, but an infinite number of times until the random number does not match one of the forbidden values? PE's documentation only says the bare minimum about loops, and is proving to be not much help.

I know I could technically just do #RANDOMTEXT instead, but that seems... overly messy and cumbersome, and I feel like I'm missing something obvious.

EDIT:
The code for the macro in question right now is:

Code: Select all

{#settemp -name testloopflag -content 1}{#loop {#settemp -name shopID -content {#calc {#rnd 116}+1}} -count {#gettemp testloopflag -variablename testloopflag}}{#url http://www.neopets.com/objects.phtml?type=shop&obj_type={#gettemp shopID}}
(Obviously the loop condition here isn't permanent.)

Peter Stotz
PhraseExpress Expert
Posts: 897
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 17 Oct 19, 19:49

@baffleblend
My suggestion: self-referential function call instead of loop

Macro 1 - start macro
{#insert #SetShopID}{#url http://www.neopets.com/objects.phtml?ty ... ={#gettemp shopID}}

Macro 2 - autotext: #SetShopID

(* Generate a shopID random number from 1 to 117
*){#settemp -name shopID -content {#calc 1+{#rnd 117} -round 0}}(*
Invalid shopID value 6|11|19|28|29|32|33|52|64|65|99|99|109|115 ? → self-referential call of #SetShopID
*){#insert {#check -text {#gettemp shopID} -case == 6 -output #|== 11 -output #|== 19 -output #|== 28 -output #|== 29 -output #|== 32 -output #|== 33 -output #|== 52 -output #|== 64 -output #|== 65 -output #|== 99 -output #|== 109 -output #|== 115 -output # -else }SetShopID}

Peter Stotz
Windows 10 - PhraseExpress v14.0.164

Post Reply