How do I combine stuff

0 favourites
  • 5 posts
  • hey guys..

    i'm havin' a bit of trouble understanding if this can be done in c2 - someone more exp. could help me.

    so i'm tryin' to create a function that works for everything of some type. example:

    function "solids health calculate" (Arg1, arg2):
       -pick solid where uid = arg1       -      remove arg2 hp from that solid
       if hp > 0  .. do something
       if hp < 0 .. do something etc..[/code:npfbxchw]
    
    now there's a little problem with this - i have 5 big solids and 2 small solids, i want small solids to spawn different explosion then the big ones. how can i check of which type they are if they're put into a family? (i'd like to skip checking for each object type :/ or creating 2 families) 
    
    also if i got 2 items pinned to a object - can i destroy them in one event or do i have to check in each event separately (by getting them with UIDs) ? 
    
    [code:npfbxchw] 
    pick  something1  where uid = someUID
    pick something2 where uid = someUID2                   - destroy something1, destroy something2
    [/code:npfbxchw] 
    or 
    [code:npfbxchw]
    pick something1 where uid=someUID   - destroy something1
    
    pick something2 where uid = someUID2 - destory something2 
    [/code:npfbxchw]
     
    also - is it faster to update some wannabe pinned object every 1 sec/0,5sec, or use pin behaviour? 
    
    question no. 3.
    if i create a boat, add to that boat a flag in container and want that flag pinned on the top of the boat, how can i make sure that when object is created (with container) will have that flag pinned, or do i have to manually pin it every time?
    
    and last question:
    i need to create stuff that goes downwards, but i want it to appear outside layout and move downwards, how can i do that? also, i want stuff to appear for the next few minutes, how do i control when it is created (except with the "wait" function) ?
    currently i have something like this:
    [code:npfbxchw]  wait 2 sec - create island ..
         wait 5 sec  - create 2nd island 
         wait 8 sec  - create something
             wait 4 sec - create mine
             wait 10 sec - create some stuff 
                 wait ... and so on[/code:npfbxchw]
  • Give them a new family instance variable where you save their type as string or whatever (so for all big ones it is "big", for the small ones it is "small").

    For the second problem - you need to understand how picking works. You start with all objects picked basically and then reduce the selection continuously by placing your conditions.

    So if you want to select two different instances of one family in one event but you only have two different UIDs to separate them from the rest, you need to do a "pick by evaluate" and then do

    pick by evaluate: family.uid = someUID1 | family.uid = someUID2

    This way you pick the instances with someUID1 and someUID2. The "|" is the logical or operator in construct.

    If the instances are different objects like sprite1 and sprite2, you can easily do it as you've written:

    pick something1 where uid = someUID

    pick something2 where uid = someUID2 - destroy something1, destroy something2

    Don't know about pin performance, less frequent updating should use up less resources I guess, but... can't say for sure.

    3) you probably need to pin it manually, but you should try it out and see what happens, when you don't pin it. In case you want to pin it automatically on creation, but have different events creating stuff, you can use an event like:

    on created (family or sprite) - pin flag to (family or sprite)

    4) move downward = bullet behavior with bullet angle of motion set to 90°; you can deactivate setting the angle, so that the bullet behavior does not rotate your object by 90°

    Control when it is created: there is a timer behavior, use it

  • how can i check of which type they are if they're put into a family? (i'd like to skip checking for each object type :/ or creating 2 families)

    the only way I know how to do it is to set an instance variable in the family and then when you create the object, set it's family instance to some sort of identifier. i.e. kind = "green"

    so then in your function you would do:

    if object.kind = "green" do this...

    if object.kind = "blue " do this...

    also if i got 2 items pinned to a object - can i destroy them in one event or do i have to check in each event separately (by getting them with UIDs) ?

    you could pick each one, or use a container and they will automatically get deleted (and created) when you destroy/create any member of the container.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thnx for fast answer, but i've been misunderstood on a few notes.

    1. - yeah i thought there was some other way except then using variables, but forgot about strings too

    2. but i think that it doesn't work when you put pick something1 and pick something2 in the same event because - what if there isn't one of those objects? it fails (with && operator), but with | (or) it will pick only one and if it is picked - it will skip the 2nd (if it even exists), and probably fail to destroy ? or if 2nd isn't picked which one gets destroyed?

    3. oh, i could definitely use on created to pin. how do i though get the flags instance if it was created with container?

    4. i know how to move them down, but how to not destroy them outside layout? (i want them to be destroyed outside layout on the bottom side, but not on the upper side), and to spawn them offscreen a bit above the layout to glide them downwards.

    about the timer - i know for timer, but i want random spawns or different spawns (set by me), not every x seconds. because i sometimes spawn stuff after 3 sec, sometimes 10 sec passes and then something gets spawned, and etc..

  • 2. The evaluation event will pick all items that match one of the conditions, so it will pick UID1 and UID2 both together. If the uids don't match, no object is selected, or if only one matches, only one is selected of course. If you only want it to work, when you sucessfully picked two objects, then add the condition object.pickedcount = 2. If none is selected, the actions don't run, true.

    3. When the container object, that contains the flag, is picked, the flag that is contained will automatically get selected with it. So the on created event should already have the correct flag selected.

    4. Remove the "destroy outside of layout", then add an event: if object.y - object.height/2 > scrolly + originalwindowheight/2 : destroy object

    (- object.height/2 if your point of origin is in the middle of the object, if you have the origin point on the bottom of the object, it would be - object.height; if you have it on top, if would be 0)

    Well I am not sure why you think the timer behavior let's you not do that what you have described, because it does imo .

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