Welcome to the Builder Academy

Question Trigger problem with remotes

More
15 Sep 2013 18:28 #4317 by Parnassus
Can anyone see where this trigger is going wrong? Is there a way it can be done properly, please? I've tried globalling and remoting and can't get it to check the variable correctly.
Code:
1: * compare with t1284. Why does t1284 remove properly? 2: if %speech% == shuffle 3: %echo% %deck% cards in the deck. 4: set deck 10 5: global deck 6: * 7: while %var% < 10 8: eval var %var% + 1 9: set card_%var% 1 10: remote card_%var% %self.id% 11: %echo% Remote is: !card_%var%! 12: done 13: halt 14: * 15: %echo% %actor.name% shuffles %actor.hisher% deck. 16: %echo% %deck% cards in the deck. 17: * 18: elseif %speech% == deal 19: * while (%deck%) 20: %echo% %deck%. 21: * 22: set r %random.10% 23: eval thecard card_%r% 24: %echo% The card is: !%thecard%! 25: if %self.varexists(on_quest_zone_1)% 26: %echo% self varexists(on_quest_zone_1) 27: else 28: %echo% no self varexists(on_quest_zone_1) 29: end 30: if %%self.varexists(%thecard%)%% 31: %echo% Should deal a card 32: %echo% Card %thecard% 33: rdelete %thecard% %self.id% 34: eval deck %deck% -1 35: global deck 36: else 37: %echo% Can't deal a card. 38: eval deck %deck% -1 39: global deck 40: end 41: * done 42: else 43: return 0 44: end

You say, 'shuffle'
Cards in the deck.
Remote is: !card_1! (The !s are to check for spaces)
Remote is: !card_2!
Remote is: !card_3!
Remote is: !card_4!
Remote is: !card_5!
Remote is: !card_6!
Remote is: !card_7!
Remote is: !card_8!
Remote is: !card_9!
Remote is: !card_10!

The mobs stat reads:
Triggers:
Global Variables:
Global context: 0
card_10: 1
card_9: 1
card_8: 1
card_7: 1
card_6: 1
card_5: 1
card_4: 1
card_3: 1
card_2: 1
card_1: 1
deck: 10

You say, 'deal'
10. (This is the count of cards in the deck - line 20)
The card is: !card_8! (!s again show that there are no hidden spaces)
No self varexists(on_quest_zone_1) (This is just a check to see if varexists worked properly - lines 25-29)
Should deal a card (Shows that the variation exists - line 30)
Card card_8 (Again, just shows the card)

The mob now shows:
Global Variables:
Global context: 0
card_10: 1
card_9: 1
card_7: 1 (card_8 has been removed - line 33)
card_6: 1
card_5: 1
card_4: 1
card_3: 1
card_2: 1
card_1: 1
deck: 9 (one card has been removed - line 34)

You say, 'deal'
9. (Shows that 1 card out of 10 has been dealt)
The card is: !card_8! (Shows the card, note that the card is the same one as last time!
No self varexists(on_quest_zone_1) (shows that varexists is working)
Should deal a card (shows that the card has been found in varexists even though it's not there)
Card card_8

Please Log in or Create an account to join the conversation.

More
16 Sep 2013 21:45 #4324 by thomas
Replied by thomas on topic Trigger problem with remotes
Your problem occurs here:
Code:
if %%self.varexists(%thecard%)%%
due to no double-evaluation in if-sentences this will turn into %self.vareexists(card_8)% as a string.

Try this:
Code:
+ eval temp %%self.varexists(%thecard%)%% + eval hascard %temp% + if %hascard% - if %%self.varexists(%thecard%)%%
The following user(s) said Thank You: Parnassus

Please Log in or Create an account to join the conversation.

More
16 Sep 2013 22:52 - 17 Sep 2013 01:11 #4326 by Parnassus
Thanks so much for working that out for me! And I especially like that it wasn't something easy like a comma in the wrong place.

Update: It's working beautifully now :)
Last edit: 17 Sep 2013 01:11 by Parnassus. Reason: Edited for update.

Please Log in or Create an account to join the conversation.

More
22 Sep 2013 02:19 #4344 by Parnassus

thomas wrote: due to no double-evaluation in if-sentences this will turn into %self.vareexists(card_8)% as a string.


I input your code into my trigger and now the trigger is working just the way I wanted to. However, now that I've moved on to surrounding triggers, I realize that I have no idea what that means or how it works. Is there a helpfile on the complexities of using %%? There are apparently situations which call for double %s. Does anything call for triple %s?

The problem seems to be, as you pointed out, that they can be used as strings or variables. In fact, one trigger was driving me crazy with errors until I realized that I had typed set %remotename% 1 instead of set remotename 1 which kept generating a message about how 1 wasn't declared or something. This just shows that I can't even use %% properly in simple situations.

Please Log in or Create an account to join the conversation.

More
23 Sep 2013 20:57 #4346 by thomas
Replied by thomas on topic Trigger problem with remotes
Basically, % is a special character.

If a "word" is surrounded by %percent%, it means "insert the value of the variable by the name percent".
I use word in quotes because it doesn't need to be between spaces and can (and often do) contain punctuation. Basically, if it starts with a (non-doubled) percent sign, and ends with one, it's a variable.

To escape a %, it must be doubled to %%. When the string %% is evaluated, it will evaluate to a single %, with no special meaning.
The key word in the previous sentence is evaluated. The thing eval does. As opposed to set which just copies a value, eval will actually parse the input.

So, in this code:
Code:
1 set thecard card_8 2 eval temp %%self.varexists(%thecard%)%% 3 eval hascard %temp% 4 if %hascard%
will be executed like this:
Code:
1 sets the value of thecard to card_8 2 evaluates the string "%%self.varexists(%thecard%)%%" from left to right: "%%" is "%" "self.varexists(" is unchanged "self.varexists(" since there are no special chars "%thecard%" is the value of the variable named thecard, "card_8" ")" is unchanged, ) is not a special char in strings "%%" becomes "%" combined this becomes "%self.varexists(card_8)%" which is the put into the temp variable. 3 evaluates the value of %temp% (remember, % means get the value of the variable and insert it here, verbatim). This value is "%self.varexists(card_8)%", which is evaluated. The answer, either 1 or 0 is put into the hascard variable. 4 evaluates the value of the hascard variable, either 0 or 1. In this case, it performs a branching based on the value.
I haven't seen examples of using more than two percent signs at a time, but it is of course possible.

It probably helps if you, everytime you write %something% not think of it as the variable, but the value of the variable.

If it helps; this is emergent behaviour, which was never considered during the design phase. which is why it isn't documented anywhere.
The following user(s) said Thank You: Parnassus

Please Log in or Create an account to join the conversation.

More
24 Sep 2013 01:07 #4347 by Parnassus
Thank you so much for the breakdown. I'm sure that I'm not the only person who will find this information very useful. I'm going to let it bounce around my head for a while because I'm easily confused, but I really love the hint.

thomas wrote: It probably helps if you, everytime you write %something% not think of it as the variable, but the value of the variable.


This is going to help such a lot because my triggers just keep getting longer and harder for me to understand. I usually just poke at them and hope they end up working but it's much better to understand why they do what they do!

Please Log in or Create an account to join the conversation.

Time to create page: 0.239 seconds