AlexSV's Forum Posts

  • A local variable/number/value is not normally held in memory outside of the event block it is used in, so yes it resets to 1 each time. This is a key property of how local variables work as opposed to global variables. Note that this can be overwritten with the "static" option set, as described in the manual.

    https://www.construct.net/en/make-games/manuals/construct-3/interface/dialogs/event-variable

    That makes sense, thank you!

  • To clarify, it doesn't really replace and insert into the parenthesis. The number in the parenthesis is the parameter used to run the function. The entire "Function.Factorial(5)" function, as an expression, equals (or is replaced by, if you want to use that wording) whatever is set as the return value inside the function.

    So in the end that action is in effect "Set result to 120". Note this is different than "Set result to Function.Factorial(120)", which would be... a very big number.

    Ahhh ok that makes more sense.

  • Once the function is finished, the local number "output" clears out and returns to 1 the next time the function is run, right? It doesn't clear out during the loops since the function hasn't yet finished.

  • That works, I appreciate it. I am trying to make sure I understand this correctly so I can use it in the future rather than just copying someone else's work.

    When you use the expression Function.Factorial(5), this calls the function and sends the number 5 into the "N" parameter of the function.

    I physically wrote down the math step by step 5 times to understand how the loop works. I get it now, I think. 1 * (5 - 0) = 5, sets it to output. 5 * (5 - 1) = 20. Sets it to output, and so on.

    Once the loop is complete, it then takes output and makes it the return. The return is then returned to the expression that we typed earlier and inserts it into the parameter parenthesis, so that it basically says "Set result to Function.Factorial(120)". return is then set to whatever is inside the parenthesis.

    Am I getting it, roughly?

  • Thank you! I have never used a function that returned a number before!

  • So, I was able to connect with a programming buddy and he was able to walk through the process with me in a way that I could barely sort of grasp. I am now working on trying to create the formula within Construct since he was able to show me how he would do it in Python, and while he doesn't understand C3, he knows Java and Python. I have a semi-decent handle on C3, but I struggle with coding langauges.

    I have now discovered what you meant by "factorial", being like 5! meaning the result of 5*4*3*2*1. In Python, this would just be the result of "5!", but Construct, as far as I can tell, doesn't have a built in ability to do factorials. So my friend said I needed to write a function for a factorial in order to call that function and drop it into my event sheet.

    I have made a simple project where I have a number entry box and a button to click. Typing a number into the box and clicking the button should return the factorial.

    However, I am now discovering that I didn't know as much about functions as I thought I did previously. I have used functions as events in the past without a need to return a value, mostly for things like the player being hurt and subtracting health, temporary invincibility on hit and stuff like that. I had to learn how to even call a function with a return value, since it no longer appears in the event list. Since I got THAT working, my function only half works and I am a bit stuck now.

    When the program is started, if you type any number 1 or lower, it returns the same number as a result in the text. If you, at any time, type a number larger than 1, the program freezes up and no longer works.

    So I have a few things that I might be doing wrong. When I call my function using "Set Result to Functions.FactorCalculation(0)"... what does the "0" represent? That's the first item in the list of parameters that I defined, right?

    Where does the return value go? I can't seem to find anything in the Functions.FactorCalculation expression that represents the return value itself. I'm not quite sure how to actually access whatever is being returned from the expression. I feel that I may be simply misunderstanding how to use a function with a return value.

  • I've used functions before, and I swear it was always right here.

    I want to click the button, then call the function and display the result as text. But... there are no functions to call.

    Tagged:

  • Wow, this kind of blows my mind, honestly. I had read a few things on how to do this and came back to see if any tips had been posted before I got into it, but this example project not only eclipses my math skills but also is written far more beautifully and efficiently than I have ever done. I feel like a caveman on multiple fronts, haha.

    I am looking inside of it now to see what I didn't know that I didn't know. I didn't even know "Pick by Evaluate" existed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • End goal is to have the AI begin play overconfident and sloppy and then tighten up over a few lost rounds til it plays perfectly.

    In that case I feel it's better to understand the math and create the perfect play, then engineer mistakes into it.

    Do I like... I dunno, get a math tutor to explain it? Or a professor?

  • Sorry, I know this is an incredibly dense question, but I am struggling big time here and I don't know what else really to do at this point aside from hiring a person smarter than me to tackle this issue.

    So I am creating a game that, at its core, is a 1v1 game of Liar's Dice. For those who need an explaination, two players shake up 5 six sided die in a cup and place them on a table, hidden from each other's view. You may view your own hand, but you may not see the other player's hand. The starting player then wagers how many total dice are presenting a certain pip on the entire table. A wager of "Three 2s" would be claiming "There are at least three dice showing the 2-pip side".

    The next player then must either raise the wager, either by raising the number of wagered dice (Four 2s) or pips (Three 3s), or they may call the other player a Liar to reveal all hands on the table. If the player who calls is correct, then the liar loses a die. If the player who calls is incorrect, then the caller loses a die.

    Play continues until one player loses all of their dice.

    In this game, 1s count as wilds, meaning they represent any face. So a hand of 1, 1, 2, 3, 4 could call "three 3s" in absolute safety since the 1s represent the remaining 3s.

    So here's where I am getting stuck: every article that explains the math of this game just boggles my mind and I have no idea how to break this concept down. I am unsure how to program an AI for the enemy player if I can't understand the probability of the game itself. I struggled with high school math. I struggled with using Pi to calculate the tiles to be exploded in a fighting game I made two years ago.

    I have the player's hand loading into an array and the enemy hand loading into an array. I also have the enemy hand loading into a special array called "known dice" since the enemy player will cheat during the game to gain information they shouldn't normally have, but that's another day's problem for now, although I assume if I build this AI to work off of the "known dice" array now, then it will still work later when I add cheating.

    So Wikipedia breaks it down as "The expected quantity of any face value among a number of unknown dice is one-sixth the total unknown dice. A bid of the expected quantity (or twice the expected value when playing with wilds), rounded down, has a greater than 50% chance of being correct and the highest chance of being exactly correct."

    So this means first I have to take the number of unknown dice and divide it by 6. Then I take the result and double it, then round it down, and this will give a resut of a "probably true" bid if I include the known dice? Basically I need to create a conditional tree for how many unknown dice there are on the table, do that piece of math, and then compare it to what the player has claimed and go from there.... I think?

    Many of these articles are going into these massive formulas that I just can't wrap my head around. This one is basically Latin to me.

    Can anyone offer me some assistance here?

  • If you're using bullets for enemies, couldn't you use the solid behavior on the enemies to keep them from overlapping?

  • That is a lot of work on my end and it won't help you learn!

    Look, start with something small.

    Try making an AI that will move towards you or away from you. Use a timer and a random number inside of an instance variable to set AI patterns for your AI.

    Give it a try on your own before you read the next part here. I'll explain it, but you should try at least to figure it out on your own.

    You can do it like this.

    On start of layout -> Start AI Fighter "Random Picker" timer, regular 2 seconds.

    This starts a timer on our AI fighter when the layout begins. This timer repeats because it's regular.

    On "Random Picker" Timer -> set AI_Fighter "Behavior" number to int(random(3))

    Random will set the number randomly between 0 and 1 less than the number you put in, so in this case, randomly from 0 to 2. The int part rounds the number to a whole number. That means it can be 0, 1, or 2.

    Now, make your code do this.

    If "Behavior" is 0, don't simulate control.

    If "Behavior" is 1, simulate control left.

    If "Behavior" is 2, simulate control right.

    This will make an AI that sits still or moves left or right ever 2 seconds.

  • Oh, did you try Layout Scale like peter568 mentioned up above?

  • Well, essentially you have everything you need. Basically, when you are not right clicking, it does the zoom between two objects. When you are right clicking, it only zooms to the crosshair.

    If you're doing the "scroll to" method, you can just set the behavior disabled on the player while you are right clicking and enabled when you aren't.

  • Here, I grabbed some quick screenshots from my own code.

    Ok, so I have a sprite with the solid behavior. I go to that behavior and add a tag, like this. This is done in the properties bar of whatever you added solid to. It could be a sprite, tilemap, tiled background, whatever you need. I tagged my solid "house" in my project.

    Then, we write a piece of code that sets our exceptions for us. In this screenshot, I wanted my player to be able to walk through the house solid, and so I create an action from my player using "set solid collision filter". This action lets you include or exclude, and since I want my player to pass through, I picked "exclude".

    Now my player can walk through any solid tagged as "house".