CJacobsSA's Forum Posts

  • The dictionary thing does seem like a better idea, but I can't get it to work as you suggest.

    When I do this, it won't allow me, saying that the key value has to be a string... but it can't be a string because then it won't work for referencing the value of the button's variable, it will literally reference the string "obj_button.var_upgradetoadd". I'm not sure how to make it function in the way you've suggested.

  • Hi! I've got a problem that has pretty much stumped me and I feel like I'm missing something obvious. In my game, the player clicks buttons to purchase permanent upgrades (governed by a global variable that says 'yes, they have this upgrade'). That sounds pretty simple, but what I can't figure out is how to make it so that the specific button gives the specific upgrade.

    I've done this...

    ...with the buttons, where 'UpgradeToAdd' governs which upgrade to give the player. Where I am stumped is, I don't know a quick and easy way to translate this to the corresponding global variable ('Upgrade_x') being set from 0 to 1. Basically, what I want to have happen is this:

    When the player clicks the button (and can afford the price) -> The upgrade that is called the same as 'var_UpgradeToAdd' is set to '1'.

    But I can't do that using 'Set value' from what I can figure out because 'Set value' requires you to pick one variable specifically. What am I missing?

  • Wow, that's awesome! You really went above and beyond. Thanks, this is great!

  • Ah ok, I did not notice the edit, sorry. You are using array.indexof(0) to find the empty right? Also a valid way to do it, never thought of it. Anyway I have some suggestions as to the solution. I will give you two solutions actually, the first one is applicable in your case since you store type at index y=0. The second is more general if you need to check things at other y indexes.

    Thank you for the continued help, I appreciate it. That said, I think I still have no idea what I'm doing. I definitely get what you're saying, but I've got no clue how to put it into practice. Your explanation is fine, I guess the problem is I'm having trouble wrapping my head around putting it into Construct. Maybe running through it step by step would help?

    https://www.dropbox.com/s/d6nuv9fzqyd61 ... .capx?dl=0

    Here's the updated capx file in case you want to just show me what the finished product would look like (a la your favorite daytime TV cooking show) instead because that might be easier. I wouldn't blame you <img src="{SMILIES_PATH}/icon_razz.gif" alt=":P" title="Razz">.

  • Would that solve the problem, though? It seems like that would leave me with the same issue but done via a different method. How would I make it so that happens unless the object being picked up is of a type the player already has?

    I managed to do this with the system I currently have, but I don't know how to make it check if the object being picked up has the same 'type' variable as any in the inventory (line 45), and then just not do anything if that's not the case.

  • Hi, I have a pretty simple question (at least I hope it's simple).

    I'd like this event to only occur if the inventory (Array_Inventory) is not full. The problem is that I noticed there's no action to check if an array has a value in every slot. How would I go about doing such a thing?

    EDIT: I've figured out how to check if the inventory is full using a variable and the "IndexOf" expression, but now the problem is that you can't collect multiples of the same block if there's a block in every slot. It's so close, but I have no idea how to fix that!

    https://www.dropbox.com/s/d6nuv9fzqyd61 ... .capx?dl=0

    Here is the cap file, line 42 is the one that deals with my question.

  • That's close, but it's not quite what I'm looking for, and I don't know how to adapt it to my own code. I think it might be better if I just dump the whole capx file on you and let you poke around:

    https://www.dropbox.com/s/3o5xykpvzy974 ... .capx?dl=0

    The function code I'm using to handle adding/removing things from the inventory is from this tutorial, I even adapted the comments so I wouldn't forget what everything does. I really just cannot wrap my head around how to make arrays do things.

    Down at the bottom of the event sheet you can see where I tried my own prototype tinkering to get it to work, feel free to just delete all that.

  • Hi, this is a followup question to another topic I made the other day. I realized I had another question but it's a bit bigger than the other and so I think it requires its own thread.

    I'm stuck on the next step of the process. I want to be able to find a specific item ID in the array, but I can't do "Array contains value" because the X and Y values can appear multiple times or be the same number. What I need is a way to compare ONLY the X axis or ONLY the Y axis, but I can't figure that out either. I need your help again, fellow Construct 2 users!

    In addition, if anyone can help me figure out how to make the item craftable (as in, how to search for the value again upon clicking the craft button, then remove 1 of the item and give the new item) that would be much appreciated. But I realize that's possibly a little more in-depth than you may want to go.

    The basic process would be like this:

    1. Search for the appropriate item only in the first row and its amount only in the second row.

    2. If it is found and the player has enough, display the craft button. In the doodle, the stuff required to craft a new item would be 8 of whatever Item #2 is.

    3. When the player clicks the craft button, remove the required amount (and the item itself if the resulting value leaves the player with 0 of it).

    4. After doing this, add the new item and the specified amount of it to the array wherever the next blank space is.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • edit: moved my question to a new thread because it's a bit more in-depth than this one.

  • Ah, I hadn't thought of that! I can see how to do it now that you've mentioned it! Thank you!

  • Hello, I've got a problem I can't quite figure out with my inventory system. I looked in the FAQ sticky and didn't find an answer to my issue. Basically, I'm using an array to store 2 values: The slot it is in, and its item ID. I'd like to be able to swap that second value with another elsewhere in the array when the player clicks on the item in their inventory and drags it to another spot. It's kind of hard to describe what I want to happen in words so here are some doodles:

    Here's a representation of the array. The first row is the item slot, the second row is the item's ID. Each column together makes one inventory slot.

    The player clicks and drags an item from one slot to another in the game (represented by picking it up from the slot and attaching it to the mouse) and lets go.

    As a result, the two values swap places on the array. In the game this is represented by the two items swapping slots.

    The problem is that I don't know how to do that in the code. I would greatly appreciate the help because this has proven to be a real headscratcher for me.

  • That's very helpful, thank you!

  • Hi, I am making a completely shameless Terraria/Starbound ripoff (eventually it will be less shameless, I promise) and something I can't figure out is how to make the player only able to place blocks on a grid. I've figured out how to constrain their reach using a line of sight behavior on the player's hitbox object, but they can still be placed anywhere in space instead of snapping to the same 32x32 grid the tiles are on. I'm sure there is a solution here but I need your help to find it!

  • Nice! Both great solutions, thanks folks.

  • If Paddle.X <= (Your Lower Bound) | Set Paddle.X to (Your Lower Bound)

    If Paddle.X >= (Your Upper Bound) | Set Paddle.X to (Your Upper Bound)

    Thank you! That is a relatively easy solution!

    Much appreciated.