Adding a multiple items to a surveypage


Author
Message
foodstudy
foodstudy
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Forum Members
Posts: 2, Visits: 15
Hi, 

I've been writing a script that can perform in the style of an online shop. This script requires selected stimuli to reappear on a later page (i.e. basket page). I have managed to make most of this work through a surveypage but I can only get the basket page to show one item rather than all items selected. Any help would be much appreciated.

I have also tried to include this feature as a list rather than an item but was not able to present the list on the surveypage.


For each individual item page there is a trial such as:

<picture bbq_melt_item>
/ items = ("bbq_melt.jpg")
/ position = (27%, 55%)
/ size = (62%, 62%)
</picture>

<text bbq_melt_text>
/ items = ("BBQ Chicken Melt with a BBQ Dip")
/ position = (75%, 37%)
/ size = (40%, 40%)
/ fontstyle = ("Arial Black", 4%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<text bbq_melt_description>
/ items = ("A melt loaded with mozzarella cheese and layers of roast chicken and red onion, served with a BBQ sauce for dipping. Comes with dipping sauce. Serves 1.")
/ position = (75%, 42%)
/ size = (20%, 20%)
/ fontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<text bbq_melt_kcals>
/ items = ("766kcal")
/ fontstyle = ("Arial Black", 3.5%, true, false, false, false, 5, 1)
/ position = (75%, 72%)
/ size = (25%, 25%)
/ txbgcolor = transparent
</text>

<text bbq_melt_price>
/ items = ("£7.99")
/ position = (75%, 85%)
/ size = (40%, 40%)
/ fontstyle = ("Arial Black", 2.59%, true, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<button return>
/ caption = "Return to menu"
/ position = (10%, 10%)
/ size = (12%, 8%)
/ fontstyle = ("Arial", 2.8%, false, false, false, false, 5, 1)
</button>

<button add_to_order>
/ caption = "Add to order"
/ fontstyle = ("Arial", 3.3%, false, false, false, false, 5, 1)
/ position = (75%, 93%)
/ size = (12%, 5%)
</button>

<button continue>
/ caption = "Continue"
/ fontstyle = ("Arial", 3.3%, false, false, false, false, 5, 1)
/ position = (93%, 93%)
/ size = (12%, 5%)
</button>

<trial bbq_melt>
/ stimulusframes = [5=basket, text.basket_count, complete_order, bbq_melt_item, bbq_melt_text, bbq_melt_description, bbq_melt_price, bbq_melt_kcals, picture.PH_logo, return, add_to_order]
/ validresponse = (basket, complete_order, "add_to_order", "return")
/ inputdevice = mouse
/ correctresponse = ("add_to_order")
/ recorddata = true
/ ontrialend = [if (trial.bbq_melt.correct == true) values.Basket += 1]
/ ontrialend = [if (trial.bbq_melt.correct == true) item.ordered_items.appenditem("BBQ Chicken Melt with a BBQ Dip");]
/ ontrialend = [if (trial.bbq_melt.correct == true) item.item_prices.appenditem("£7.99");]
/ ontrialend = [if (trial.bbq_melt.correct == true) values.basket_value += 7.99]
/ branch = [
  if (trial.bbq_melt.response == "add_to_order") {
   return trial.bbq_melt;
  } else if (trial.bbq_melt.response == "return") {
   return trial.melts;
  } else if (trial.bbq_melt.response == "complete_order") {
   return trial.CompleteSelectionCheck;
  } else if (trial.bbq_melt.response == "basket") {
   return trial.CompleteSelectionCheck;
  };
]
</trial>



The basket script is:


<item ordered_items>
</item>

<item prices>
</item>

<picture logo_basket>
/ items = ("pizza_hut_logo.png")
/ position = (55%, 10%)
/ size = (20%, 20%)
</picture>

<picture basketPic>
/ items = ("basket.jpg")
/ position = (95%, 10%)
/ size = (10%, 10%)
</picture>

<text basketText>
/ items = ("BASKET")
/ position = (95%, 6%)
/ size = (20%, 10%)
/ fontstyle = ("Arial Black", 3%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<text basketCount>
/ items = ("<%format(~"%i~", values.Basket)%>")
/ txbgcolor = white
/ fontstyle = ("Arial Black", 2.59%, true, false, false, false, 5, 1)
/ position = (90%, 10%)
</text>

<text basketPrice>
/ items = ("<%values.currency%> <%format(~"%.2f~", values.basket_value)%> ")
/ txbgcolor = white
/ fontstyle = ("Arial Black", 2.59%, true, false, false, false, 5, 1)
/ position = (90%, 75%)
</text>

<text items_basket>
/ items = ordered_items
/ fontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
/ txcolor = black
/ position = (70%, 40%)
</text>

<text prices_basket>
/ items = item_prices
/ fontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
/ txcolor = black
/ position = (90%, 40%)
</text>

<radiobuttons continue>
/ caption = "Are you finished with your order?"
/ options = ("Confirm order", "Empty basket and start again")
/ position = (75%, 80%)
/ fontstyle = ("Arial", 2.50%, false, false, false, false, 5, 1)
</radiobuttons>

<surveypage basket>
/ stimulusframes = [5=prices_basket, basketPrice, logo_basket, basketCount, basketPic, basketText]
/ showpagenumbers = false
/ showquestionnumbers = false
/ questions = [1=radiobuttons.continue; 2]
/ branch = [
    if (radiobuttons.continue.response == "Confirm order") {
        return surveypage.end;
    } else if (radiobuttons.continue.response == "Empty basket and start again") {
        return trial.again;
    }
]
</surveypage>

Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 12K, Visits: 100K
foodstudy - 5/31/2024
Hi, 

I've been writing a script that can perform in the style of an online shop. This script requires selected stimuli to reappear on a later page (i.e. basket page). I have managed to make most of this work through a surveypage but I can only get the basket page to show one item rather than all items selected. Any help would be much appreciated.

I have also tried to include this feature as a list rather than an item but was not able to present the list on the surveypage.


For each individual item page there is a trial such as:

<picture bbq_melt_item>
/ items = ("bbq_melt.jpg")
/ position = (27%, 55%)
/ size = (62%, 62%)
</picture>

<text bbq_melt_text>
/ items = ("BBQ Chicken Melt with a BBQ Dip")
/ position = (75%, 37%)
/ size = (40%, 40%)
/ fontstyle = ("Arial Black", 4%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<text bbq_melt_description>
/ items = ("A melt loaded with mozzarella cheese and layers of roast chicken and red onion, served with a BBQ sauce for dipping. Comes with dipping sauce. Serves 1.")
/ position = (75%, 42%)
/ size = (20%, 20%)
/ fontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<text bbq_melt_kcals>
/ items = ("766kcal")
/ fontstyle = ("Arial Black", 3.5%, true, false, false, false, 5, 1)
/ position = (75%, 72%)
/ size = (25%, 25%)
/ txbgcolor = transparent
</text>

<text bbq_melt_price>
/ items = ("£7.99")
/ position = (75%, 85%)
/ size = (40%, 40%)
/ fontstyle = ("Arial Black", 2.59%, true, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<button return>
/ caption = "Return to menu"
/ position = (10%, 10%)
/ size = (12%, 8%)
/ fontstyle = ("Arial", 2.8%, false, false, false, false, 5, 1)
</button>

<button add_to_order>
/ caption = "Add to order"
/ fontstyle = ("Arial", 3.3%, false, false, false, false, 5, 1)
/ position = (75%, 93%)
/ size = (12%, 5%)
</button>

<button continue>
/ caption = "Continue"
/ fontstyle = ("Arial", 3.3%, false, false, false, false, 5, 1)
/ position = (93%, 93%)
/ size = (12%, 5%)
</button>

<trial bbq_melt>
/ stimulusframes = [5=basket, text.basket_count, complete_order, bbq_melt_item, bbq_melt_text, bbq_melt_description, bbq_melt_price, bbq_melt_kcals, picture.PH_logo, return, add_to_order]
/ validresponse = (basket, complete_order, "add_to_order", "return")
/ inputdevice = mouse
/ correctresponse = ("add_to_order")
/ recorddata = true
/ ontrialend = [if (trial.bbq_melt.correct == true) values.Basket += 1]
/ ontrialend = [if (trial.bbq_melt.correct == true) item.ordered_items.appenditem("BBQ Chicken Melt with a BBQ Dip");]
/ ontrialend = [if (trial.bbq_melt.correct == true) item.item_prices.appenditem("£7.99");]
/ ontrialend = [if (trial.bbq_melt.correct == true) values.basket_value += 7.99]
/ branch = [
  if (trial.bbq_melt.response == "add_to_order") {
   return trial.bbq_melt;
  } else if (trial.bbq_melt.response == "return") {
   return trial.melts;
  } else if (trial.bbq_melt.response == "complete_order") {
   return trial.CompleteSelectionCheck;
  } else if (trial.bbq_melt.response == "basket") {
   return trial.CompleteSelectionCheck;
  };
]
</trial>



The basket script is:


<item ordered_items>
</item>

<item prices>
</item>

<picture logo_basket>
/ items = ("pizza_hut_logo.png")
/ position = (55%, 10%)
/ size = (20%, 20%)
</picture>

<picture basketPic>
/ items = ("basket.jpg")
/ position = (95%, 10%)
/ size = (10%, 10%)
</picture>

<text basketText>
/ items = ("BASKET")
/ position = (95%, 6%)
/ size = (20%, 10%)
/ fontstyle = ("Arial Black", 3%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<text basketCount>
/ items = ("<%format(~"%i~", values.Basket)%>")
/ txbgcolor = white
/ fontstyle = ("Arial Black", 2.59%, true, false, false, false, 5, 1)
/ position = (90%, 10%)
</text>

<text basketPrice>
/ items = ("<%values.currency%> <%format(~"%.2f~", values.basket_value)%> ")
/ txbgcolor = white
/ fontstyle = ("Arial Black", 2.59%, true, false, false, false, 5, 1)
/ position = (90%, 75%)
</text>

<text items_basket>
/ items = ordered_items
/ fontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
/ txcolor = black
/ position = (70%, 40%)
</text>

<text prices_basket>
/ items = item_prices
/ fontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
/ txcolor = black
/ position = (90%, 40%)
</text>

<radiobuttons continue>
/ caption = "Are you finished with your order?"
/ options = ("Confirm order", "Empty basket and start again")
/ position = (75%, 80%)
/ fontstyle = ("Arial", 2.50%, false, false, false, false, 5, 1)
</radiobuttons>

<surveypage basket>
/ stimulusframes = [5=prices_basket, basketPrice, logo_basket, basketCount, basketPic, basketText]
/ showpagenumbers = false
/ showquestionnumbers = false
/ questions = [1=radiobuttons.continue; 2]
/ branch = [
    if (radiobuttons.continue.response == "Confirm order") {
        return surveypage.end;
    } else if (radiobuttons.continue.response == "Empty basket and start again") {
        return trial.again;
    }
]
</surveypage>

You need separate stimulus elements for every object you want to display on the basket page. Use insertstimulusframe() to add a selected stimulus object to the basket surveypage's stimulusframes. Use resetstimulusframes() to revert the surveypage to its default state (no added objects)  when the basket is emptied

Edited Last Month by Dave
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 12K, Visits: 100K
Dave - 5/31/2024
foodstudy - 5/31/2024
Hi, 

I've been writing a script that can perform in the style of an online shop. This script requires selected stimuli to reappear on a later page (i.e. basket page). I have managed to make most of this work through a surveypage but I can only get the basket page to show one item rather than all items selected. Any help would be much appreciated.

I have also tried to include this feature as a list rather than an item but was not able to present the list on the surveypage.


For each individual item page there is a trial such as:

<picture bbq_melt_item>
/ items = ("bbq_melt.jpg")
/ position = (27%, 55%)
/ size = (62%, 62%)
</picture>

<text bbq_melt_text>
/ items = ("BBQ Chicken Melt with a BBQ Dip")
/ position = (75%, 37%)
/ size = (40%, 40%)
/ fontstyle = ("Arial Black", 4%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<text bbq_melt_description>
/ items = ("A melt loaded with mozzarella cheese and layers of roast chicken and red onion, served with a BBQ sauce for dipping. Comes with dipping sauce. Serves 1.")
/ position = (75%, 42%)
/ size = (20%, 20%)
/ fontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<text bbq_melt_kcals>
/ items = ("766kcal")
/ fontstyle = ("Arial Black", 3.5%, true, false, false, false, 5, 1)
/ position = (75%, 72%)
/ size = (25%, 25%)
/ txbgcolor = transparent
</text>

<text bbq_melt_price>
/ items = ("£7.99")
/ position = (75%, 85%)
/ size = (40%, 40%)
/ fontstyle = ("Arial Black", 2.59%, true, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<button return>
/ caption = "Return to menu"
/ position = (10%, 10%)
/ size = (12%, 8%)
/ fontstyle = ("Arial", 2.8%, false, false, false, false, 5, 1)
</button>

<button add_to_order>
/ caption = "Add to order"
/ fontstyle = ("Arial", 3.3%, false, false, false, false, 5, 1)
/ position = (75%, 93%)
/ size = (12%, 5%)
</button>

<button continue>
/ caption = "Continue"
/ fontstyle = ("Arial", 3.3%, false, false, false, false, 5, 1)
/ position = (93%, 93%)
/ size = (12%, 5%)
</button>

<trial bbq_melt>
/ stimulusframes = [5=basket, text.basket_count, complete_order, bbq_melt_item, bbq_melt_text, bbq_melt_description, bbq_melt_price, bbq_melt_kcals, picture.PH_logo, return, add_to_order]
/ validresponse = (basket, complete_order, "add_to_order", "return")
/ inputdevice = mouse
/ correctresponse = ("add_to_order")
/ recorddata = true
/ ontrialend = [if (trial.bbq_melt.correct == true) values.Basket += 1]
/ ontrialend = [if (trial.bbq_melt.correct == true) item.ordered_items.appenditem("BBQ Chicken Melt with a BBQ Dip");]
/ ontrialend = [if (trial.bbq_melt.correct == true) item.item_prices.appenditem("£7.99");]
/ ontrialend = [if (trial.bbq_melt.correct == true) values.basket_value += 7.99]
/ branch = [
  if (trial.bbq_melt.response == "add_to_order") {
   return trial.bbq_melt;
  } else if (trial.bbq_melt.response == "return") {
   return trial.melts;
  } else if (trial.bbq_melt.response == "complete_order") {
   return trial.CompleteSelectionCheck;
  } else if (trial.bbq_melt.response == "basket") {
   return trial.CompleteSelectionCheck;
  };
]
</trial>



The basket script is:


<item ordered_items>
</item>

<item prices>
</item>

<picture logo_basket>
/ items = ("pizza_hut_logo.png")
/ position = (55%, 10%)
/ size = (20%, 20%)
</picture>

<picture basketPic>
/ items = ("basket.jpg")
/ position = (95%, 10%)
/ size = (10%, 10%)
</picture>

<text basketText>
/ items = ("BASKET")
/ position = (95%, 6%)
/ size = (20%, 10%)
/ fontstyle = ("Arial Black", 3%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
</text>

<text basketCount>
/ items = ("<%format(~"%i~", values.Basket)%>")
/ txbgcolor = white
/ fontstyle = ("Arial Black", 2.59%, true, false, false, false, 5, 1)
/ position = (90%, 10%)
</text>

<text basketPrice>
/ items = ("<%values.currency%> <%format(~"%.2f~", values.basket_value)%> ")
/ txbgcolor = white
/ fontstyle = ("Arial Black", 2.59%, true, false, false, false, 5, 1)
/ position = (90%, 75%)
</text>

<text items_basket>
/ items = ordered_items
/ fontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
/ txcolor = black
/ position = (70%, 40%)
</text>

<text prices_basket>
/ items = item_prices
/ fontstyle = ("Arial", 2.5%, false, false, false, false, 5, 1)
/ txbgcolor = transparent
/ txcolor = black
/ position = (90%, 40%)
</text>

<radiobuttons continue>
/ caption = "Are you finished with your order?"
/ options = ("Confirm order", "Empty basket and start again")
/ position = (75%, 80%)
/ fontstyle = ("Arial", 2.50%, false, false, false, false, 5, 1)
</radiobuttons>

<surveypage basket>
/ stimulusframes = [5=prices_basket, basketPrice, logo_basket, basketCount, basketPic, basketText]
/ showpagenumbers = false
/ showquestionnumbers = false
/ questions = [1=radiobuttons.continue; 2]
/ branch = [
    if (radiobuttons.continue.response == "Confirm order") {
        return surveypage.end;
    } else if (radiobuttons.continue.response == "Empty basket and start again") {
        return trial.again;
    }
]
</surveypage>

You need separate stimulus elements for every object you want to display on the basket page. Use insertstimulusframe() to add a selected stimulus object to the basket surveypage's stimulusframes. Use resetstimulusframes() to revert the surveypage to its default state (no added objects)  when the basket is emptied

If you don't want to display images of the added objects, you can also do something else.

The key mistake in your approach is this here:

/ ontrialend = [if (trial.bbq_melt.correct == true) item.ordered_items.appenditem("BBQ Chicken Melt with a BBQ Dip");]


You're adding an item to an <item> element for every object added to the cart. So, suppose you add 4 objects, then that <item> element will have 4 distinct items. A stimulus, however, only ever displays a single item, it cannot ever display multiple distinct items at once.

In other words: There must ever be only a single item. And that item must be a growing list of the objects you added. You can achieve that by having the stimulus display a variable (i.e. <values> entry) that starts out as an empty string ("") and then you simply concatenate any objects added (plus some formatting stuff, line breaks, etc) to that string as you go along. When the cart is emptied, you reset the value to the empty string. Simple example:

<values>
/ nItemsInCart = 0
/ itemsInCart = ""
</values>

<trial a>
/ stimulusframes = [1=text.a, button.yes, button.no]
/ inputdevice = mouse
/ validresponse = (button.yes, button.no)
/ ontrialend = [
    if (trial.a.response == "yes") {
        values.nItemsInCart += 1;
        values.itemsInCart = concat(values.itemsInCart, "<p>Object A</p>")
    };
]
</trial>

<trial b>
/ stimulusframes = [1=text.b, button.yes, button.no]
/ inputdevice = mouse
/ validresponse = (button.yes, button.no)
/ ontrialend = [
    if (trial.b.response == "yes") {
        values.nItemsInCart += 1;
        values.itemsInCart = concat(values.itemsInCart, "<p>Object B </p>")
    };
]
</trial>

<text a>
/ items = ("A")
/ position = (50%, 50%)
</text>

<text b>
/ items = ("B")
/ position = (50%, 50%)
</text>

<text cartcontents>
/ items = ("<%values.itemsInCart%>")
</text>


<button yes>
/ caption = "Add to cart."
/ size = (25%, 15%)
/ position = (30%, 85%)
</button>

<button no>
/ caption = "No, thanks."
/ size = (25%, 15%)
/ position = (70%, 85%)
</button>

<surveypage basket>
/ caption = "You have <%values.nItemsInCart%> item(s) in your cart."
/ stimulusframes = [1=text.cartcontents]
/ showpagenumbers = false
/ showquestionnumbers = false
</surveypage>

<block myblock>
/ trials = [1-2 = noreplace(trial.a, trial.b); 3 = surveypage.basket]
</block>

foodstudy
foodstudy
New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)New Member (6 reputation)
Group: Forum Members
Posts: 2, Visits: 15
This is so helpful, thank you so much!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search