Loop through an Array at a certain XY coordinate?

0 favourites
  • 4 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Hi guys,

    So I'm still learning construct 2 (been about 2 weeks) and I'm trying to get my head around loops. I'm trying to build a branching outcomes system from scratch (it's probably way above my knowledge level, but I'm forging ahead), and am trying to do something where I have an array. It has a opening dialogue prompt, then 2 choices. But sometimes the choices will have requirements (like 'give me 10 gold'). I want to be able to run a check to see if the player meets that requirement, and, if not, grey it out.

    Eg:

    (0,0,0) Hi, want to stay at the inn?

    (1,0,0) Yes (10 Gold)

    (1,1,0) No (exit)

    At (1,0,1) I'd have GOLD, to signify we're looking for Gold (not...Copper or some other resource)

    At (1,0,2) I'd have 10 to signify that it's ten of that resource (in this case 10 gold)

    So I'm trying to build a for loop that says when you come across a dialogue option, search the Z axis and compare it against global varables to see if PlayerGold>Gold they're charging. If it is, I'll be able to run an event where it's unselectable, if not, and it's clicked, it'll reduce the player gold by 10. That bit I'm not too worried about.

    Ultimately I think I can do almost everything, but for some reason I can't get it to search just one axis - I can't figure out how to use loops to limit the search.

    I want to do something like:

    If ChatArray.X = 1 and ChatArray.Y = 0 Search ChatArray.Depth for CurrentValue="Gold"

    Then I'd set a local variable 'resource' to "Gold" at ChatArray.CurZ and local variable 'amount' to ChatArray.CurZ+1 and be able to manipulate the values from there.

    Does any of that make sense?

    At its most basic - how do I run a loop that searches a at a set X and a set Y position to see if there's a specific string (eg "gold") and, if there is, return that value to a local variable, and the value after it (ie 'the amount of gold as a number) to another variable.

    I'd link a .capx, but don't know how yet. Also, the event will look horrendous

    Thanks for any help you can offer!

    Dman

  • Hi guys,

    So I'm still learning construct 2 (been about 2 weeks) and I'm trying to get my head around loops. I'm trying to build a branching outcomes system from scratch (it's probably way above my knowledge level, but I'm forging ahead), and am trying to do something where I have an array. It has a opening dialogue prompt, then 2 choices. But sometimes the choices will have requirements (like 'give me 10 gold'). I want to be able to run a check to see if the player meets that requirement, and, if not, grey it out.

    Eg:

    (0,0,0) Hi, want to stay at the inn?

    (1,0,0) Yes (10 Gold)

    (1,1,0) No (exit)

    At (1,0,1) I'd have GOLD, to signify we're looking for Gold (not...Copper or some other resource)

    At (1,0,2) I'd have 10 to signify that it's ten of that resource (in this case 10 gold)

    So I'm trying to build a for loop that says when you come across a dialogue option, search the Z axis and compare it against global varables to see if PlayerGold>Gold they're charging. If it is, I'll be able to run an event where it's unselectable, if not, and it's clicked, it'll reduce the player gold by 10. That bit I'm not too worried about.

    Ultimately I think I can do almost everything, but for some reason I can't get it to search just one axis - I can't figure out how to use loops to limit the search.

    I want to do something like:

    If ChatArray.X = 1 and ChatArray.Y = 0 Search ChatArray.Depth for CurrentValue="Gold"

    Then I'd set a local variable 'resource' to "Gold" at ChatArray.CurZ and local variable 'amount' to ChatArray.CurZ+1 and be able to manipulate the values from there.

    Does any of that make sense?

    At its most basic - how do I run a loop that searches a at a set X and a set Y position to see if there's a specific string (eg "gold") and, if there is, return that value to a local variable, and the value after it (ie 'the amount of gold as a number) to another variable.

    I'd link a .capx, but don't know how yet. Also, the event will look horrendous

    Thanks for any help you can offer!

    Dman

    There is possibly a bit of misconception of what array coordinates are on your part I'm afraid.

    In your original list :

    (0,0,0) Hi, want to stay at the inn?
    (1,0,0) Yes (10 Gold)
    (1,1,0) No (exit)[/code:28zps16j]
    
    Is read in Construct as Array.at(X, Y, Z)
    So ChatArray.At(0,0,0) is your question. The question is the value (text in this case) that is found at the coordinates ChatArray.at(0,0,0)
    
    So for your answers, you actually need to use a single location, but multiple possible values. Consider "Yes" is 1 and "No" is 0
    You can simply store 0 or 1 in ChatArray.At(0,1,0) (the second Y of your first X (remember this is zero-based).
    
    So you then use array conditions :
    
    Compare at X, Y, Z - X 0; Y 1; Z 0 = 0
    This event executes actions when the user answers "No" to staying in the inn.
    On the other hand, another event :
    Compare at X, Y, Z - X 0; Y 1; Z 0 = 1
    Will mean that the user wants to stay.
    
    From there, you can set the price in (0,1,1) and (0,1,2)
    Again, instead of storing actual "text" (for example "Gold") you can store a number for multiple values (0 is Gold, 1 is Copper, 2 is Silver, and so on)
    
    So when you
    Compare at X, Y, Z - X 0; Y 1; Z 1 = 0 
    You know you mean Gold, and will look to remove ChatArray.at(0,1,2) from your Gold variable.
    If Compare at X, Y, Z - X 0; Y 1; Z 1 = 1
    You might mean Copper, and so will look to remove ChatArray.at(0,1,2) from your Copper variable.
    
    And so on.
    Then, you can store in the next X (1,0,0) the next question/situation/prices.
    
    To be fair, third-dimensions arrays are pretty intricate and complicated. If you always know that you'll be dealing with prices or stuff of the like, possibly a simple two dimension array (just using X and Y coordinates) may perfectly do the job, adding more Y cells to each X.
  • Thanks Kyatric, that's certainly helping.

    With some other 'choose your own adventure' style stuff I've done so far, I've successfully been able to use text strings in Arrays to do some interesting stuff. Like setting a random number between 1&10 to give me a random x coordinate, set that as a variable, then using that set all the responses along the Y and Z axis - where I put the responses on the Y axis, and the corresponding outcomes on the Z axis of that X,Y coordinate.

    It's probably pretty untidy, but it works so far. I THINK I understand Array Coordinates and how they're used okay, just maybe not explaining myself well.

    In fact, so far I've been able to pull all the information I've needed from the Array so far, the only problem being that if I loop through the XYZ of the Array, I think it returns the values at the FIRST instance of that String, as opposed to the specific one I want. So, in the actual Capx, I'm trying to find if the word BATTLE appears inside any Z cell at a certain XY coordinate. I just can't figure out what event to run to do that.

    I've uploaded a screen shot of where I'm at - and the event I put in. That returns the right information, but only because the String I'm searching for is the only one in the Array. If there were multiple instances of that String in the Array, it, I think, would only give me the first one.

    https://1drv.ms/i/s!ApdGZ3eiGElxhY5bvG87hAO04rc0hw

    Thanks so much for the help.

    Liam

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • But absolutely point taken about using numbers to allow the information in an array cell to be far more useable.

    I think the hard part is - when it's 'if response x clicked, go to array cell y', that's fine, I can do that. The hard part I'm trying to figure out is 'if response x is called, check to see if player has the gold, if they don't, then don't call response x'. If you follow me. So...run the test before deciding if the player sees it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)