Please help I'm stupid and illiterate

0 favourites
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • So basically I have this code, where, when an enemy(aka Hurtables)dies(hp is below or equal 0), they drop an item, like, ammo for missiles, or hp. This event plays BEFORE the event where the enemy destroys itself.

    Before, I had instance variables called Drop and DropRandom. Drop was either yes or no, and it basically said if the enemy dropped an item or not. DropRandom was a variable that, when the enemy dies, rolled a number from 0 to 5. If the number is 2, it spawned hp, and if it's 5, it spawned a missile pickup. Yes, it's dumb. But it worked.

    What's not working is this. I replaced the Drop variable with a variable called DropProbability. If I wanted a Hurtable to not spawn anything, I would set the DropProbability to 0. And if I wanted a Hurtable to always spawn something, I would set the probability to 100 or 99. And that worked.

    However, 98 is a different story. It's a number that is very close to 100, yet, when enemies die with DropProb set to 98, they only spawn anything half the time, and I checked that multiple times. And when I actually set DropProb to 50, IT DOESN'T SPAWN *ANYTHING*. Here's the main event:

    [attachment=0:ynnarnoi][/attachment:ynnarnoi]

    There's also only 1 event for each pickup when it is destroyed, that is, when it's picked up. That busts my theory that pickups instantly self-destroy when they spawn for no reason. :/

  • https://www.dropbox.com/s/htodmstra9gz2 ... er093.capx

    Sorry, here's the capx. The code is in the "Common Sense" group.

  • Bam Bump.

  • Hey,

    I have yet to fully learn how families work but as I understand it a family group is considered a separate object to the objects that are children of it.

    What this means is when you have your actions call the families group it does not get your instanced variable for the object that is a child of it but the family object itself.

    I have not found a way so far to reference dynamically the child objects of a family. And believe me I have been trying as it would save me about 200 events in my event sheets.

  • Hey,

    I have yet to fully learn how families work but as I understand it a family group is considered a separate object to the objects that are children of it.

    What this means is when you have your actions call the families group it does not get your instanced variable for the object that is a child of it but the family object itself.

    I have not found a way so far to reference dynamically the child objects of a family. And believe me I have been trying as it would save me about 200 events in my event sheets.

    Yes, but families also have instance variables which are given to the objects inside that family. You do that by pressing right click on the family and selecting the "add instance variable". In this case, hp is a variable of the family.

  • > Hey,

    >

    > I have yet to fully learn how families work but as I understand it a family group is considered a separate object to the objects that are children of it.

    >

    > What this means is when you have your actions call the families group it does not get your instanced variable for the object that is a child of it but the family object itself.

    >

    > I have not found a way so far to reference dynamically the child objects of a family. And believe me I have been trying as it would save me about 200 events in my event sheets.

    >

    Yes, but families also have instance variables which are given to the objects inside that family. You do that by pressing right click on the family and selecting the "add instance variable". In this case, hp is a variable of the family.

    Yes I know this but you still can not reference dynamically the object inside the family by using the family object as the event object. By doing this you are checking against the instance variables of the family object and not the object you want. I have not found a way as of yet to actually reference the object inside the family without making convoluted if - else if events for each and every object.

  • >

    > > Hey,

    > >

    > > I have yet to fully learn how families work but as I understand it a family group is considered a separate object to the objects that are children of it.

    > >

    > > What this means is when you have your actions call the families group it does not get your instanced variable for the object that is a child of it but the family object itself.

    > >

    > > I have not found a way so far to reference dynamically the child objects of a family. And believe me I have been trying as it would save me about 200 events in my event sheets.

    > >

    > Yes, but families also have instance variables which are given to the objects inside that family. You do that by pressing right click on the family and selecting the "add instance variable". In this case, hp is a variable of the family.

    >

    Yes I know this but you still can not reference dynamically the object inside the family by using the family object as the event object. By doing this you are checking against the instance variables of the family object and not the object you want. I have not found a way as of yet to actually reference the object inside the family without making convoluted if - else if events for each and every object.

    Wait, but the code doesn't reference any family objects, only the family variables..

  • Wait, but the code doesn't reference any family objects, only the family variables..

    Exactly, you are grabbing the variables not from the object you want but the arbitrary family object which will have different values to that of the objects variables you want.

    Like I said though I am still getting to grips with families but from my experience and testing so far it seems you cannot reference variables on the fly of child objects like you are trying to do when you are looking for the drop probability variable.

    The best I have found so far is to make an array such as the following:

    And for every monster assign it an NPC ID and look up the values you want in the array.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [quso far it seems you cannot reference variables on the fly of child objects like you are trying to do when you are looking for the drop probability variable. OBJECTION! Before, I had both the Drop( yes or no) and DropRandom variable, and it worked perfectly!
  • [quso far it seems you cannot reference variables on the fly of child objects like you are trying to do when you are looking for the drop probability variable. > OBJECTION! Before, I had both the Drop( yes or no) and DropRandom variable, and it worked perfectly! > Maybe I am wrong then, it's just from my tinkering what I have found. I was not able to reference object variables inside a family by doing what you are doing.
  • How about you debug a bit?

    Print DropRandom and Hurtables.DropProbability, I would bet you're not picking the right Hurtables

  • How about you debug a bit?

    Print DropRandom and Hurtables.DropProbability, I would bet you're not picking the right Hurtables

    I tried, but nothing prints, probably because enemies die.

  • Well, just print the variables just before you destroy them

  • There seems to be a logic flaw in your probability/drop code

    [quote:1cxzta8o]Set DropRandom to round(random(Hurtable.DropProbability,100))

    This is setting DropRandom to a number between DropProbability and 100

    With DropProbability = 98, DropRandom will be 98, 99 or 100

    With DropProbability = 50, DropRandom will be 50, 51, 52, ... , 98, 99 or 100

    That is DropRandom >= DropProbability

    You are then checking:

    [quote:1cxzta8o]DropRandom <= DropProbability

    but it will never be less, and only sometimes equal.

    Basically, at 98 you have a 1 in 3 chance of a drop and at 50 you have a 1 in 51 chance of a drop.

    Try this instead:

    [quote:1cxzta8o]Set DropRandom to round(random(0,100))

    DropRandom <= DropProbability

    DropRandom will be a number from 0 to 100 and DropProbability should then work like the percentage chance you seem to have intended and if DropProbability is greater than or equal to DropRandom it will drop an item.

  • There seems to be a logic flaw in your probability/drop code

    [quote:2imn5rc5]Set DropRandom to round(random(Hurtable.DropProbability,100))

    This is setting DropRandom to a number between DropProbability and 100

    With DropProbability = 98, DropRandom will be 98, 99 or 100

    With DropProbability = 50, DropRandom will be 50, 51, 52, ... , 98, 99 or 100

    That is DropRandom >= DropProbability

    You are then checking:

    [quote:2imn5rc5]DropRandom <= DropProbability

    but it will never be less, and only sometimes equal.

    Basically, at 98 you have a 1 in 3 chance of a drop and at 50 you have a 1 in 51 chance of a drop.

    Try this instead:

    [quote:2imn5rc5]Set DropRandom to round(random(0,100))

    DropRandom <= DropProbability

    DropRandom will be a number from 0 to 100 and DropProbability should then work like the percentage chance you seem to have intended and if DropProbability is greater than or equal to DropRandom it will drop an item.

    Thank you very much! How do I give you cookies for this?

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