How do I show a random node from a XML

0 favourites
  • 5 posts
From the Asset Store
Node Downloader is a plugin for download file for Construct 3 and construct 2 game engine
  • [attachment=0:3691gj57][/attachment:3691gj57]

    I'm trying to show a random question from a XML. The variable sporsmalsnr holds a random number. For each node a counter increments. Then I want to loop through all nodes, and show the node where counter = sporsmalsnr. Somehow it doesn't work, as it only shows the first question.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well, giving it the limitations (round(random(1,2))) will do that, as you're only letting it have one number and that is 1. Try making it (round(random(0,10)))

  • I have tested it. round(random(1,2)) gives integer 1 or 2. I have two questions in the XML, but only first question is showing.

    Even when question number is 2 and counter is 2, it just shows the first question anyway. So it seems that if they are similar, it starts from the first node.

  • Isn't it zero based? so 1st node is 0...2nd node is 1.. Try using round(random(0,1)) instead

  • XPath use 1-based index, so to get the first question, use this :

    /questions/question[1]/@text"[/code:1z9wnwkk]
    For the 2nd :
    [code:1z9wnwkk]/questions/question[2]/@text"[/code:1z9wnwkk]
    And so on so forth.
    
    In your case you could just ditch the for each node and directly use the action set text to :
    [code:1z9wnwkk]XML.StringValue("/questions/question[" & sporsmal & "]/@text")[/code:1z9wnwkk]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)