NPBruce / valkyrie

Valkyrie GM for Fantasy Flight Board Games
Apache License 2.0
506 stars 105 forks source link

Test variable: add OR condition #934

Closed antontimmermans closed 5 years ago

antontimmermans commented 6 years ago

Description of Problem or Question

Following request is an enhancement request for creating scenarios in Valkyrie.

For my new scenario I am thinking about one story with different board layouts (selected random at start) and a random selected correct outcome. To complicated for me to just start building in Valkyrie, so I actually started designing it first on paper before I put it in Valkyrie.... Crazy world eh ;-)? But while making the design I found out that programming the scenario could be less complicated if the variable test in an event have the option to add an OR condition.

Currently you can test multiple variables but they are interpreted as: "Condition1 == TRUE" AND "round == 3".. then process the actions of the event. If I want also another combination of conditions to trigger the same actions I have to create a new event with the same actions but different test conditions. This could lead to a large number of events with same actions but different conditions.

I know this could be solved with "silent" tests events all calling the same action event for more consistent behavior and less chance of programming bugs. But it would be nice if there was an option to combine this in one event (for ease of programming, testing and maintenance).

A typical use-case could be that I only want the actions to happen in certain rounds, depending if other conditions are met: IF ("tileXrevealed == TRUE" AND "Hint1Discovered == TRUE" AND " Round == 2" ) OR ("tileYrevealed == TRUE" AND "Hint1Discovered == TRUE" AND " Round == 4" ) OR ("tileYrevealed == TRUE" AND "Hint1Discovered == TRUE" AND " Round == 7" ) THEN Action: Spawn something

So yes, there is a workaround but with this option some scenarios could be written less in a complicated way.

redwolf2 commented 6 years ago

We could have an option to use lua to script conditions, that way we have two paths for conditions, the current, very simple system and a more advanced, complex one, that allows for even more crazy conditions.

DelphiDie commented 6 years ago

Not to disregard your idea @redwolf2 , but I think it would be better to somehow get the "OR" checks done in the simple system, instead of creating essentially a second syntax for more complex checks.

Otherwise it would add complexitiy with marginal benefit and it will increase the entry barrier to learn the ins and outs of Valkyrie.

redwolf2 commented 6 years ago

You are right.

DelphiDie commented 6 years ago

I don't think I'm necessarily right (or that you are wrong), it's just my opinion.

But since you are one of the programmers and have a lot more knowledge about the inner workings of Valkyrie I think you are much more qualified to form an opinion than me. So I don't want to discourage you to think of new way to improve Valkyrie.

redwolf2 commented 6 years ago

No, you are right, it is better to flesh out the simple conditions first before adding something like scripting. I sometimes tend towards looking at a bigger, golden hammer, instead of focussing what is the more simple route.

kozka commented 5 years ago

Hello from my humble opinion and seeing the possibilities of lula, for me and I guess for many who know how to program in general. Trying to fill all the gaps with the "simple" interface seems to me more complicated for the developers, than to adapt in some way the way of adding it to the script. In addition and imagining the possibilities, I imagine creating standard functions, which you can call repeatedly to shorten the programming. a greeting

antontimmermans commented 5 years ago

Standard functions would be nice, I now make 'standard Quest Events' which are always called but use variables to influence their behavior.

Example: EventQMoveOneSpace is always called and will display text "you may move one space into the revealed area" Only if the variable MoveOneSpaceAllowed is set to 1 (and it will set that variable back to 0)

[EventQMoveOneSpace]
buttons=1
event1=
operations=MoveOneSpaceAllowed,=,0
conditions=MoveOneSpaceAllowed,!=,0

There would be more 'programming features' interresting that could simplify placing tiles and conditionally add tokens like: -->add ELSE condition: IF (condition is met) THEN execute event... ELSE do something else or --> return to calling event: IF (condition is met) THEN do something; Return to calling event.

In this example I repeat each follow-up event in case the previous event condition is not met.

[EventAOfficePlaceTile]
xposition=1.925227
yposition=1.817539
buttons=1
event1=EventAOfficePlaceWall
add=TileAOffice
remove=TokenAExploreLobbyOffice
operations=MoveOneSpaceAllowed,=,1 OfficeRevealed,=,1
audio=AudioEntrance

[EventAOfficePlaceWall]
xposition=1.796671
yposition=6.033134
buttons=1
event1=EventAOfficePlaceItems EventAOfficePlaceGhosts EventQPlaceDarkness EventQMoveOneSpace
add=TokenAOfficeWall

[EventAOfficePlaceItems]
comment=Place items
buttons=1
event1=EventAOfficePlaceGhosts EventQPlaceDarkness EventQMoveOneSpace

... etc....

Making the OR function available would make my next scenarion easier to program. I now put each OR in a separate event wich leads to an explosion of events: Example: Place the maid ghost depending on some conditions:

[EventGhostPlaceMaid]
display=false
buttons=1
event1=EventGhostPlaceMaid2A1 EventGhostPlaceMaid2A2 EventGhostPlaceMaid2A3 EventGhostPlaceMaid2A4 EventGhostPlaceMaid2A5 EventGhostPlaceMaid2B1 EventGhostPlaceMaid2B2 EventGhostPlaceMaid2B3 EventGhostPlaceMaid2B4 EventGhostPlaceMaid2B5 EventGhostPlacePastor

But in the end I guess for valkyrie we need to find the balance of what is still programmable with a relative simple interface to keep it accessible for non-experienced programmers

(full examples available on request but not sharing them here in order to not spoil top much of my new scenario :D)

BenRQ commented 5 years ago

Do you have any suggestion on how we could show the "OR" / AND option ? My first idea would be to add a small button between each tests to change from "and" to "or"

image

In your example you also use parenthesis IF ("tileXrevealed == TRUE" AND "Hint1Discovered == TRUE" AND " Round == 2" ) OR ("tileYrevealed == TRUE" AND "Hint1Discovered == TRUE" AND " Round == 4" ) OR ("tileYrevealed == TRUE" AND "Hint1Discovered == TRUE" AND " Round == 7" )

How do you imagine this in the quest editor ? I have to say this is much more complex to present in a nice way.

antontimmermans commented 5 years ago

It could be a similar interface as adding buttons. but then instead of adding buttons with possibly multiple events connected, you add OR conditions with multiple AND test conditions.

I tried to draw it in paint: This piece should test if ((#round >0) AND (#round) <5)) OR (#round == 6) image

PS.: I hope I program better then I paint :D

kozka commented 5 years ago

another simpler way would be to add the following (or ==) (or>) (or> =) (or <=) (or <>) to the list of signs that already exist

if ((a == 1 and b == 1) or (c == 1 and d == 1)) t1

although thinking about it You could also add the and == and> = and ... ....

if ((a == 1 or b == 1) and (c == 1 or d == 1)

I think that all cases are covered

redwolf2 commented 5 years ago

"or ==" and "and ==" look strange to me.

What do you think about this: valkyrie_draft

When pressing the "+" button, you can add "(", ")", "AND", "OR" from the list. The up and down buttons would change the item order and move the item up or down. In a perfect world the up and down arrows would be only one button, a hamburger icon ☰ you could use to drag and drop the item down the list (also saves GUI space). The list would also support this using fancy animations, but this design is much easier to implement and to understand.

kozka commented 5 years ago

it is true XDD

your idea is clearer but also something bigger.

now it comes to my mind also if a place to see in the form of a tree would be possible all these interactions between events. Open another post.

redwolf2 commented 5 years ago

Yes, the parenthesis could be shown like a tree.

(
    round
    OR
    end
    AND
    (
        we
        AND
        have
        AND
        (
            to
            AND
            go
            AND
            deeper
        )
    )
)
AND
start

But this would pose a problem when it gets too deep. Then we need to be able to scroll horizontally. If we someday have the need to handle such complex querys, we could always add scripting. So we better use a flat structure until then.

(
round
OR
end
AND
(
we
AND
have
AND
(
to
AND
go
AND
deeper
)
)
)
AND
start
kozka commented 5 years ago

if that would be fine what you say. I also think it's better to add scripts.

but I was referring to a site to see all. all the events and chains of events that you have created. and the relationships between them. and in addition to see it being able to edit it or perhaps select it. but I think this is another question / idea

redwolf2 commented 5 years ago

We already had a request on discord by zcaalock for a node based approach for events, which would be really nice, but also pose too much work to implement. Something like: https://sharpaccent.com/?c=lesson&cid=27&id=265

redwolf2 commented 5 years ago

Another simple improvement for variable conditions would be just to move it up to the trigger event, because the "test" works the same as the "trigger" and is something that triggers the event.

antontimmermans commented 5 years ago

Another simple improvement for variable conditions would be just to move it up to the trigger event, because the "test" works the same as the "trigger" and is something that triggers the event.

That could have been a solution if this was chosen before any scenario was written. But this would mean that all existing scenarios have to be rewritten. I am not a fan of doing that. Or both condition-handling methods have to be supported: the new "conditionally trigger event" AND the old "execute event only if condition is met". Both keeping support for both would be very complicated to support and might result in messy (read buggy) scenarios. so.. with Valkyrie being what it is now I would not vote for this.

antontimmermans commented 5 years ago

"or ==" and "and ==" look strange to me.

What do you think about this: valkyrie_draft

When pressing the "+" button, you can add "(", ")", "AND", "OR" from the list. The up and down buttons would change the item order and move the item up or down. In a perfect world the up and down arrows would be only one button, a hamburger icon ☰ you could use to drag and drop the item down the list (also saves GUI space). The list would also support this using fancy animations, but this design is much easier to implement and to understand.

This design could work for me too, it is clear what the outcome of the test will be. But indeed it eats-up a lot of GUI space. I would leave it up to the programmer to go more in my design direction or this one. whatever is easier to implement.

redwolf2 commented 5 years ago

Another simple improvement for variable conditions would be just to move it up to the trigger event, because the "test" works the same as the "trigger" and is something that triggers the event.

That could have been a solution if this was chosen before any scenario was written. But this would mean that all existing scenarios have to be rewritten. I am not a fan of doing that. Or both condition-handling methods have to be supported: the new "conditionally trigger event" AND the old "execute event only if condition is met". Both keeping support for both would be very complicated to support and might result in messy (read buggy) scenarios. so.. with Valkyrie being what it is now I would not vote for this.

@antontimmermans No, this is just a change in the GUI and won't affect the scenario format at all. Just move up "Test" below "Trigger".

BenRQ commented 5 years ago

I like your proposal for presentation Redwolf. I will probably make two '+' button: one to add a test and one to add ( )

It will ensure that we always have both parentheses and test is always valid.

BenRQ commented 5 years ago

Reporting some progress :

image

Creation and manipulation of test is working.

Todo still :

BenRQ commented 5 years ago

I have also changed the "dark blue" colour of the "event link" to Cyan, it was too dark I think. Tell me if you think it's a bad idea.

redwolf2 commented 5 years ago

Nice work. The color change is a General gold idea. The old blue had a bad contrast. Check out https://terminal.sexy/, if you needmore colors.

antontimmermans commented 5 years ago

Nice work indeed, I am looking forward to test it. I agree that the new blue contrast is an improvement. And speaking of contrast, I wouldn't mind if the tile display area (not the editor panel) would be a just a tiny little brighter. Or shall I create a new request for this?

BenRQ commented 5 years ago

A new ticket would be better, with a screen capture if possible, to be sure I understand your request.

BenRQ commented 5 years ago

Most of the development is done, and only the parenthesis management remains. But I have to think this part a bit.

The rest of the feature is fully functional. If someone is ready to test, I can share a test version here.

I don't believe in perfect code at the first delivery, so you should find some bugs :P

antontimmermans commented 5 years ago

Volunteer<<< This weekend I should have time to test it

BenRQ commented 5 years ago

Hi @antontimmermans , you will find the version here: https://we.tl/t-MBrQHXBatK

I've shared a zip so you can keep you official version and compare the behaviour if required.

antontimmermans commented 5 years ago

Adding variable test and moving them up/down works fine and works intuitive. Deleting a test using the red - button works for all tests except for the first and the last one: cannotremovefirstandlastentry

I tried to create a test in my work in progress scenario to see if the AND/OR evaluation is perfromed correctly. After the inial UI is handled, this scenario will place a test clue token. With this test token i can select which version of the manor should be placed, and which version of the story to select. The token will be placed but when selecting the token, the test menu didn't pop up like in Valkyrie 2.1.3 . Test Scenario: ChapelDownManorTEST.zip fyi, Manor 1 will work (2 is not implemented yet); The Placement of a Person (the patron) token in the Office tile includes the new test. In storyline 1 ,3 and 4 he shouldappear there depending on the round nr. For testing this you best select manor 1, story 1

antontimmermans commented 5 years ago

Tested the Editor adding up to 51 tests. Editing works fine, the UI response becomes slower on my computer when adding a new line or when toggling AND to OR above 40 test entries

BenRQ commented 5 years ago

Thanks a lot for the test report, and the test scenario ! I will try not to spoil myself too much :)

Adding variable test and moving them up/down works fine and works intuitive.

Cool :)

Deleting a test using the red - button works for all tests except for the first and the last one:

Delete issue is fixed.

I tried to create a test in my work in progress scenario to see if the AND/OR evaluation is performed correctly.

I'm not sure I understand if you have been able to do this test. If yes, can you confirm it works as expected ? Please note that there are no priority, all tests are run from start to end. In your test example (picture) , I suspect you are waiting for this (manor==1 and story == 1 and Patron == 1 and round == 3) OR (manor==1 and story == 1 and Patron == 1 and round == 3) But it will do this: ((((((manor==1 and story == 1 ) and Patron == 1 ) and round == 3) OR manor==1) and story == 1) and Patron == 1 ) and round == 3) For me the latter is the intended tests.

The token will be placed but when selecting the token, the test menu didn't pop up like in Valkyrie 2.1.3 .

Also fixed :)

Tested the Editor adding up to 51 tests. Editing works fine, the UI response becomes slower on my computer when adding a new line or when toggling AND to OR above 40 test entries

For performance, I will check if I can do something. But 40 tests sounds a bit extreme :)

antontimmermans commented 5 years ago

(cut the firstpart to shorten the message)

I'm not sure I understand if you have been able to do this test.

No , I could not test it since I didn't get response from the token. I couldn't access my testbuttons.

If yes, can you confirm it works as expected ? Please note that there are no priority, all tests are run from start to end. In your test example (picture) , I suspect you are waiting for this (manor==1 and story == 1 and Patron == 1 and round == 3) OR (manor==1 and story == 1 and Patron == 1 and round == 3) True.. But it will do this: ((((((manor==1 and story == 1 ) and Patron == 1 ) and round == 3) OR manor==1) and story == 1) and Patron == 1 ) and round == 3) For me the latter is the intended tests.

This is not as I had expected indeed but i guess i can work with that. I will try out later if i can work around the button problem.

The token will be placed but when selecting the token, the test menu didn't pop up like in Valkyrie 2.1.3 .

Also fixed :)

Cool, i might need this fixed version to test properly. I will let you know later.

Tested the Editor adding up to 51 tests. Editing works fine, the UI response becomes slower on my computer when adding a new line or when toggling AND to OR above 40 test entries

For performance, I will check if I can do something. But 40 tests sounds a bit extreme :)

True, but hey.. testing is testing ;-). Wanted to see if there was a limit but stopped at 50. Still impressive that i could go that far without the program breaking.

BenRQ commented 5 years ago

I will share a new version this evening, with some of the 'parenthesis' support. It will still be quite technical version, so you may want to test first without parenthesis.

BenRQ commented 5 years ago

I'm almost done with parenthesis support, but unfortunately some blocking issues remain when deleting elements in the test. I will share a version, as soon as it can be tested.

antontimmermans commented 5 years ago

I made a Mini Testscenario for AND/OR test It chooses a random value (1-2) for variabes A, B and C. It displays the value of the variables (Lefft to right A, B, C) with tokens: Value == 1 -> SearchToken Value == 2 -> ExploreToken Then it executes the tests and displays the test of which evalutation tested correct: A==1 AND B==1 AND C==1 A==1 AND B==1 OR C==1 A==1 OR B==1 AND C==1 A==1 OR B==1 OR C==1

The sight token infront should allow you to randomize the values again without restarting the scenario. But I could not click this button with the test version of Valkyrie that I now have.

ANDORTEST.zip

antontimmermans commented 5 years ago

Small update on test scenario. It still ANDORTEST.zip works as described above. at start A,B and C are give random values. by clicknig the tokens you should be able to set them from 1 to 2. Thjis scenario fives you better control over what you want to test. The sight token no longer randomizes but just displays the test result. But with the test valkyrie version i have i could not activate any token so i hope it works for you @BenRQ

BenRQ commented 5 years ago

Hi @antontimmermans, here is an update of the version, with all the latest fix discussed. I've tested with your first scenario and it's working fine. If you check the logs, you can see the test results.

https://we.tl/t-a7jfvd9Bnm

Parenthesis are working, you can create them, move them, and they should work as expected in the tests you create. Also if you try to delete some parts of the tests, you should not be able to 'break' the test, it should always have a valid syntax. That part took me some time :)

Only way to break the test is to invert opening and closing parenthesis, but I will soon fix that too.

I have not implemented the delete option on parenthesis. Tell me if you think it's necessary.

image

antontimmermans commented 5 years ago

Tested with latest scenario:

When all parenthesis are placed in a correct way the evaluation of ALL tests went as expected: like: (A=1 AND B=1) OR C=1 versus A=1 AND (B=1 OR C=1) WELL DONE! Bored by so much perfection, time to see if i can break it :) (life of a tester is partly being sadistic)

Gramatically wrong since the parenthesis is place before the AND and not after. But program didn't break and it is evaluated as A=1 AND (B=1 OR C=1) moveupdownandincorrect

Tried reversing the parenthesis ) close first , and then open ( instead of ( ). Again, program didn't break and its is evaluated as if the parenthesis where placed correctly.

Also adding empty parenthesis ( ): before test; after the test; both before and after; somewhere inbetween: No problemo.

Time to pull out the big gun. bigguntest Any other value setting then a,b,c = 1 (for example, 211; 121, 222) would stil display this result: biggunresult In this scenario test calling secquence is (when the sight token is clicked): EventTest ->EventTest1 (a==1, b==1, c==1) ->EventTest2 (contains the messed up test as depicted above) <- any input value combination ends up here ->EventTest3 ->EventTest4 ->EventTest5 ->EventTestNONETRUE

I have to admit. that if programs this B..S.. for real then I would also not care what the test result would be. the good thing was: Program still didn't break. Overall, it looks very good, It's quite a complex feature to add and so far I coud not break it. With this level of stability and functionality I would aready be pleased and it could be used for my level of complextiy in scenario tests.

I have added the latest version of the tesscenario including the 'bigguntest': ANDORTEST.zip

BenRQ commented 5 years ago

Sounds like you enjoy torturing my version :)

Grammatically wrong since the parenthesis is place before the AND and not after

In the first screen capture, the '(' is before the AND operator. How did you get that ? It should not be possible to end up in this situation.

I will try to add a security to make this impossible : parenthesis ) close first , and then open (

For the other tests, I understand everything is working nicely. Almost done!

Do you think a delete button on the '(' ')' is required ?

antontimmermans commented 5 years ago

Sounds like you enjoy torturing my version :)

Haha. Yes i do, and when you google my name you will probably find the 'correct me' through my job-title.

Grammatically wrong since the parenthesis is place before the AND and not after

In the first screen capture, the '(' is before the AND operator. How did you get that ? It should not be possible to end up in this situation.

I don't know the exact sequence I clicked but I was moving the parenthesis up and down an bit. I think somewhere in that clicking sequence I might have swapped )( too .. and back ().

I will try to add a security to make this impossible : parenthesis ) close first , and then open (

Would be nice, less chance of making a mess like the biggun test. And may even solve the '(' before the AND problem

For the other tests, I understand everything is working nicely. Almost done!

Do you think a delete button on the '(' ')' is required ?

Since empty '()' is not influencing the evaluation of the test, it is not blocking if you leave the delete button out. But is doesn't look really nice and I am certain that scenarios will have empty '()' because people will click the '+ (..)' button also when not intended (reflex or not sure what it does).

I am not sure what you are struggling with to add the delete button. If it is to delete the correct ')' when you delete a '(', I don't think you have to worry about that.

In both cases it is up to the scenario writer to move any remaining parenthesis to their correct position.

An other angle could be to implement this in a code cleaner/beautifier:

Anyway, an experienced Scenario writer will edit events.ini for sure and will have no issue finding and deleting them if it bothers him/her. But adding a '-' button in one of the proposed ways is a cleaner solution.

Hope this helps.

kozka commented 5 years ago

I'm glad you're moving forward, But it would not be easier to insert a script. for someone who does not know how to program, it's going to cost the same, learn that, put a code. but good that if it consecena good for you. :)

BenRQ commented 5 years ago

@kozka I think it's probably easier to construct the test in the app : easy variable selection in the app, no syntax error, no keyword to know. And/or/ ( ) are some basic mathematical notions that most people knows.

I think it's worth the effort, and it should help non developer to make more complex scenario.

BenRQ commented 5 years ago

@antontimmermans here is the final version with the delete button on parenthesis. I have also added some check, so you won't be able to do crazy move with any components. You should not be able to break now !

Good luck trying ^^

https://we.tl/t-V2TxzuMVH6

antontimmermans commented 5 years ago

Ok, I will have a look at it tomorrow.

Verzonden vanuit Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 voor Windows 10


Van: BenRQ notifications@github.com Verzonden: Wednesday, November 21, 2018 9:46:51 PM Aan: NPBruce/valkyrie CC: antontimmermans; Mention Onderwerp: Re: [NPBruce/valkyrie] Test variable: add OR condition (#934)

@antontimmermanshttps://github.com/antontimmermans here is the final version with the delete button on parenthesis. I have also added some check, so you can't make crazy move with any components so you should not be able to break now !

Good luck trying ^^

https://we.tl/t-V2TxzuMVH6

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/NPBruce/valkyrie/issues/934#issuecomment-440803530, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AoH5NGoriqJ3Sppb4LXgC-x8nKIrFAiXks5uxbu7gaJpZM4X8FxJ.

antontimmermans commented 5 years ago

Keeping the order of '('berofe')' looks fine including deleting them. delete etiher '(' or ')'" does indeed delete the pair. --> solved

The parentesis is also nicely placed behind AND and not infront. --> This also seems solved

Evaluation of the test tesult is also correctly interpreting the parentesis.--> No regression

So far so good... again time for another big gun but a bit smaller this time.

I started with this situation: parenthesisok

Then I moved the top pair down so I could switch '(' 1 with '(' 2. I then managed to create this: parenthesisnok

This is evaluated incorrectly: parenthesisnokresult

I then managed to delete the top ')' which did not delete '(': parenthesisnoktopdeleted

the deletion of the final pair '()' worked as expected, leaving this end result: parenthesisnokdeletefail

BenRQ commented 5 years ago

Thanks @antontimmermans It's now fixed :) I will probably make a test version for #950 later, if you want to give it a final test

I've updated "quest format" version number.

@redwolf2 @scrubbless @DelphiDie FYI, this change is a breaking change for older version of the app. It means version 2.1.x won't be able to load scenario generated by version >= 2.2 2.2 can still read older scenario though.

With current and previous version of Valkyrie, scenarios with unsupported quest format are just not listed in download section.

Difficult to say if people have been updating a lot their 2.0 version. Anyway it's another topic, I'm closing this issue as the work is DONE !

redwolf2 commented 5 years ago

In that case we have to increment the quest format version and document it here: https://github.com/NPBruce/valkyrie/wiki/QuestFormat

BenRQ commented 5 years ago

I've incremented quest format in the latest commit : https://github.com/NPBruce/valkyrie/commit/366ad49b7062679b0ef71ae742a0b5495ed7d800

But it's strange, it has now reached 10 but the documentation state it should already be 10.

BenRQ commented 5 years ago

Documentation is updated. I've fixed the documentation so the latest improvements of 2.0 version are listed in format "9"

antontimmermans commented 5 years ago

It looks as if the tests in OLD scenarios disappear and have to re-programmed