Explore the community Forums Lectora Lectora Questions & Answers Storing to array and displaying a log

Tagged: , ,

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #298009 Score: 0
    Profile photo of Craig Sybert
    Craig Sybert
    Member
    @Contrast

    I am trying to log some information to be presented in a list format. For example. I want a button to register one of 6 different choices and assign a number to it. So, if they choose button #3 and set the number to 5, it would create an ‘entry’ for that turn in a game. I would like to be able to send the user to a log page that would list all the items logged for that game in order of turn and show which button they choose and how many points were assigned to it. It is akin to creating an array and displaying that array on demand. Any help is appreciated! Thank you.

    #298189 Score: 0
    Profile photo of Wendy Miller
    Wendy Miller
    Member
    beginner
    intermediate
    contributor
    advanced
    friend finder
    junior moderator
    wise owl
    profile
    verified member
    55 pts
    @wendymiller

    Hi Contrast,

    I was having a hard time imagining what it is you are trying to do, so I asked my colleague, Daryl Fleary @dfleary, to take a look at your post with me. And it reminded him of a piece he put together for one of his Inspiration Wednesday sessions. As you probably already know, Lectora does not have true array variable types or methods (other than variable X “contains”), but with a little creativity you can usually find a way to get almost anything done.

    Daryl passed along his example from the IW session to me which I am attaching to this post. It is a Lectora 11 Library Object, but will work in Lectora 12 as well. I’m sure it’s not exactly what you’re looking for, but may give you an idea of how you can achieve what you’re really trying to do. It uses a series of hidden entry fields to store a value for each button/marble to emulate an array. Then a series of actions groups run when the submit button is clicked which count up the number of each color. Here is a link to the recording of Daryl’s session. He explains it much better than I do. His description of this interaction begins at about 41:15.

    https://community.trivantis.com/knowledge-base/designing-questions-in-v11/

    I hope this helps some.

    Attachments:
    1. Marbles.zip
    #298249 Score: 0
    Profile photo of Craig Sybert
    Craig Sybert
    Member
    @Contrast

    My initial thought was to create psudo entries and fill them in, so not far from what I was looking for. I am currently not able to get to streaming media content at work, so will view this when I get home. I did want to get a little more detail here to see if my description prompts any other responses.

    Details.

    I have a score keeper. Each person starts at 20. During each turn, one or both of the players may loose points due to a specific event. I wanted to log that event and the corresponding loss of points and be able to list those, per turn. So, a sample out put would be “Turn 4 – Player 1, -5, landing on red spot” or “Turn 5 Player 1, -1, rolling 7, Player 2, +1, opponent rolling 7”

    I hope that gives a little more insight. I think that the solution you presented is certainly viable, but the number of turns in a game could be upwards of 20 each, so that is a lot of pre-set variables to program. Thank you again for all your help!

    #298261 Score: 0
    Profile photo of Daryl Fleary
    Daryl Fleary
    Member
    beginner
    intermediate
    advanced
    friend finder
    LUC16
    LUC16 Attendee
    contributor
    wise owl
    verified member
    17 pts
    @dfleary

    Hi Contrast:

    It looks like you attempted to upload your AWT file. Try choosing File > Export > Zip (or export to PKG) and I’ll take a look if/when I get a little time. It sounds like fun. 🙂

    What you are attempting is certainly doable. I (and others) have created games that keep track of multiple players, turns, scores, etc. and depending on the game event (or a question’s response) scores increase or decrease, turns are lost, bonus points are awarded, and so on. Sometimes I am able to do all of it in a string/array (adding to and subtracting from a single variable) and other times I need to use independent variables for each item. It just depends on what I am attempting (and how well my brain is functioning that day). For example, you might have a string for each player that contains all of the necessary information and then, as Wendy suggests, you use “contains” to look in the variable:

    Player1=t4|Land on Red|73

    Player2=t7|Land on Blue|48

    Player3=t2|Rolling 7|-55

    So in this case you’d see that player 1 is on turn number 4; he/she landed on red, and his/her updated point total is 73. You can show messages, update scoreboards, etc. if the string contains… whatever you are looking for.

    You’d get to the string by looping through a series of updates for each turn. Something like this:

    OnMouseClick, RunActionGroup Update Turn

    Update Turn group:

    • Modify variable P1Turn, Add + 1, If ActivePlayer=1
    • Modify variable P2Turn, Add + 1, If ActivePlayer=2
    • Modify variable P3Turn, Add + 1, If ActivePlayer=3
    • Run Action Group Update Event

    Update Event group:

    • Modify variable Event, Set Equal to Land on Red, If …
    • Modify variable Event, Set Equal to Land on Blue, If …
    • Modify variable Event, Set Equal to Rolling 7, If…
    • Etc.
    • Run Action Group Update Points

    Update Points group:

    • Modify variable NewPoints, Set = 25, If Event Equal To Land on Blue
    • Modify variable NewPoints, Set = -15, If Event Equal To, Land on Red
    • Modify variable NewPoints, Set = -1, If Event Equal To, Rolling 7
    • Etc.
    • Run Action Group Set Player

    Set Player group:

    • Run Action Group Player 1 String, If ActivePlayer=1
    • Run Action Group Player 2 String, If ActivePlayer=2
    • Run Action Group Player 3 String, If ActivePlayer=3

    Player 1 String group:

    • Modify variable P1Points, Add, VAR(NewPoints)
    • Modify Player1, Set Equal To, tVAR(P1Turn)|VAR(Event)|VAR(P1Points)
    • Run Action Group Next Player If…

    Player 2 String group:

    • Modify variable P2Points, Add, VAR(NewPoints)
    • Modify Player2, Set Equal To, tVAR(P2Turn)|VAR(Event)|VAR(P2Points)
    • Run Action Group Next Player If…

    Player 3 String group:

    • Modify variable P3Points, Add, VAR(NewPoints)
    • Modify Player3, Set Equal To, tVAR(P3Turn)|VAR(Event)|VAR(P3Points)
    • Run Action Group Next Player If…

    Next Player group:

    • Modify variable ActivePlayer, Add 1, If ActivePlayer <3, Else ModVar ActivePlayer, Set Equal To 1

    So as long as you have a group to manage each parameter, and link them together, you can build your strings and it would handle an unlimited number of turns for each player. (You just don’t update the ActivePlayer variable until you are ready to switch.)  I used this technique to build a Wheel-of-Fortune-Type-Game, keeping track of players scores, who’s turn, spin value, available letters, how many occurrences of a letter in the phrase, buying vowels, losing turns, etc. It just looped through for each spin and selection.

    Hope this helps give you some ideas.

    Daryl, Lectora/Lectora Online Product Manager

    #299443 Score: 0
    Profile photo of Craig Sybert
    Craig Sybert
    Member
    @Contrast

    Attaching the file. it is still about mid way in development, but I wanted to give some more detail to the project. This is actually a scoring app for a game called Magic the Gathering. If you are familiar with it, you will understand. If you are not, the basic problem I am having is that I want to track the last 5-6 turns and show “what” has dealt damage to “who” and “how much” was dealt.

     

    Posted this and then realized I hadn’t thanked you for the examples. It is very close to what I am looking for and will be putting nose to grindstone now that I have time to get back to this project.

    • This reply was modified 4 years, 1 month ago by Profile photo of Craig Sybert Craig Sybert.
    Attachments:
    1. LCOUNT.zip
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.