How to form formulas

This forum is currently in read-only mode.
0 favourites
  • In text and not only. is there a list of all the emmm "codes"? commands? i dont know how to call it. few examples of what i think as "codes"

    random(360)[/code:3co6gxlq]
    
    [code:3co6gxlq]"what do you think?" & newline & Global('ROTFL')[/code:3co6gxlq]
    
    in my current case i would like Construct's text object to display a percen value of something.
    i have two main variables, which are "Shields_Total" and "Shields_Current"
    and i would like the text object to display not the actual value but what % it is of "Shields_Total".
    
    any idea how to form that? 
    
    another one is a condition based also on % of some value. for example
    IF value "Shields_Current" equals to or lower then 50% of "Shields_Total" then... 
    
    as you know, the values changes with ship upgrades ect but i want the effect to stick to the % values. so when ever the ship shield value/variable is on 50/10 or 5000000/10000000 condition will get trigered.
  • They're called Expressions. You can find a list of the built-in System Expressions.

    If you have two global variables 'a' and 'b' and want to know what percentage of 'b' is 'a', just use:

    global('a') / global('b')

    This will give you 0.5 for 50% (which is mathematically correct). If you want it as a scale up to 100 for 100% just multiply by 100:

    (global('a') * 100) / global('b')

    To create an event that runs when 'a' is under 50% of 'b', use System -> Compare Values to create:

    (global('a') * 100) / global('b') is less than 50

    This will run every tick when it's true, so if you play a warning sound, it'll keep playing all the time. To prevent that, add a 'Trigger Once' condition beneath it, then the actions (playing a sound or whatever) will run once the first time the percentage drops below 50.

  • ooooh man, "expresions"... sorry for wasting your time. now i feel so stupid. i just tried googling wiki and forums with "commands" and "codes" and coudnt find anything... thats because "expresions" is what i should be looking for. this is when my terrible english shows out. i should figure this one out.

    Thank you Ashley! ill manage from here

  • Don't beat yourself up, you gotta learn it one way or another!

  • umm and what about expression for file path?

    i mean i have a sound in game folder, how to tell the Construct the path? like

    AppPath/SFX/

  • use apppath & "filename.extension"

    example

    http://dl.dropbox.com/u/5811650/apppath.rar

    Edit: oh, and the cap/exe and the file must be in the same folder

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ahh perhaps i messed up something when describing my problem.

    i want the file to be played/loaded from custome location. as i have custome game folder structures. so instead of dumping everything into main folder i make sub-folders named after their functions "SFX" "Music" "Graphics" ect.

    dont tell me something so obvious cant be done under Construct O_o

  • Try: AppPath & "Subfolder\filename.ext"

  • Try: AppPath & "Subfolder\filename.ext"

    my God, so obvious. was right under my nose.

    Thank you Ashley!

    I have another question but i dont want make yet another topic(otherwise i will dominate the whole Help&Support section by the end of the month lol) so ill ask here in this thread.

    i have problem with setting up a basic "ON/OFF" switch based on variables. of course - if you now a way to do this other then by variables feel free to enlighten me.

    what i want/need:

    When pressing "F1" i want something to move from one place to another, and when pressing F1 again to go back. imagine it like a UI moving from outside of the screen down vertical into the screen, and then going back. bear in mind its not about X/Y position, but actual sliding from point A to B and from B to A.

    what i used:

    ive set up variable "Switching"

    IF key F1 pressed=>
                If variable =0 : 
                               1. move Object verticaly 150
                               2. Set variable to 1
                                     
                if variable =1:
                              1. move Object verticaly -150
                              2. Set variable to 0[/code:3srr8btz]
    
    and that should work... but it doesnt. most of the time it goes randmly up and down like it would ignore the chanching variable. is there a way to make so that F1 key will be disabled until the variables switches? 
    
    basicly - how would you write an event that when you press a key, moves the object alternate left and right.
    
    i tried crazy things and i am fighting with this dumb problem from over 2h
    
    EDIT:
    now 3h lol
  • That's a common issue - events are run in order, so immediately after it toggles the variable, the next event toggles it right back. Instead, use:

    • if key F1 pressed, set variable to 1-variable (set the variable to 1-itself)
    • - if variable = 0, set position to .x+150
    • - if variable = 1, set position to .x-150
  • i have problem with setting up a basic "ON/OFF" switch based on variables. of course - if you now a way to do this other then by variables feel free to enlighten me.

    what i want/need:

    When pressing "F1" i want something to move from one place to another, and when pressing F1 again to go back. imagine it like a UI moving from outside of the screen down vertical into the screen, and then going back. bear in mind its not about X/Y position, but actual sliding from point A to B and from B to A.

    what i used:

    ive set up variable "Switching"

    IF key F1 pressed=>
                If variable =0 : 
                               1. move Object verticaly 150
                               2. Set variable to 1
                                     
                if variable =1:
                              1. move Object verticaly -150
                              2. Set variable to 0[/code:1yfih4yu]
    
    and that should work... but it doesnt. most of the time it goes randmly up and down like it would ignore the chanching variable. is there a way to make so that F1 key will be disabled until the variables switches?
    

    Arima's solution is an elegant one for this case, but it may not apply well to all conditional branching situations that you may come across, so I'll point out another way: ELSE.

    ELSE is a system condition that can be used to make sure that only one of the conditions is true in any tick. You had the logic very close to correct for that case:

    IF key F1 pressed=>
                If variable =0 : 
                               1. move Object verticaly 150
                               2. Set variable to 1
                                     
                ELSE:
                              1. move Object verticaly -150
                              2. Set variable to 0[/code:1yfih4yu]
    
    Also you could extend it to a 3-state or more check in similar fashion:
    
    [code:1yfih4yu]IF key F1 pressed=>
                If variable =0 : 
                               1. move Object verticaly 150
                               2. Set variable to 1
                ELSE
                If variable =1 :
                              1. move Object verticaly -150
                              2. Set variable to 2
                ELSE
                If variable =2 :
                              1. spin Object 360 degrees
                              2. Set variable to 0[/code:1yfih4yu]
  • i tried this

    - if key F1 pressed, set variable to 1-variable (set the variable to 1-itself)
    -- if variable = 0, set position to .x+150
    -- if variable = 1, set position to .x-150[/code:45guzdhm]
    
    and its not working. well, more propable i just implemented it wrong.
    But i dont understand, so whenever i press F1 the variable  will be changed to 1
    
    so how the second sub-event gone trigger? 
    what have i done wrong?
    <img src="http://img198.imageshack.us/img198/5130/problemup.png">
    
    EDIT oh sorry guys, i havent seen your posts before. lemme check your info and see if it works 
    
    thank you  
    
    EDIT2
    
    okey i have tried this:
    [quote:45guzdhm]
    IF key F1 pressed=>
                If variable =0 :
                               1. move Object verticaly 150
                               2. Set variable to 1
                                     
                ELSE:
                              1. move Object verticaly -150
                              2. Set variable to 0
    
    
    and it works [i]almost[/i] right. the problems shows when i press the F1 rapidly. then it offten move twice down and one up or the opposite. ill try and add "every 500milisec" as condition to F1 key pressed and see how itll work.
    
    EDIT3
    nope. it fixed one problem adding another one. now - yes, the event cant be triggered twice or more in row with the same moving values but also, because of the times it now works just half of the time lol so every 1/4 F1 hit acutlay works, then again when i decrese the times to the point when it works 100% of the time, the event overlaping stricks back.
    
    EDIT4
    WOHOW! ive found an solution. its anything but elegant but it works!
    heres the deal:
    <img src="http://img151.imageshack.us/img151/2751/problemoc.png">
    i needed to add timer and a new variable, and it didnt worked at first. but when i changed the timer for 1000milisecs now its all good.
    
    thankc guys for support and stimulating my brain cells
  • The first image is almost correct. The reason it didn't work is because of the action in the first event. You have it so the variable is set to 1. Instead, set it to:

    Set global variable 'BattleEjectorsWeapons' to 1-global('BattleEjectorsWeapons')

    Get the logic? Because the way you had it, the variable was always set to 1.

  • nah its working already i am too scared to mess with it to not break it lol

    and NOW i finaly understood this "1-global('BattleEjectorsWeapons')"

    didnt knew i can use such expression this will get very handy as my spaceships armor aside from having durability they also have % dmg ressistance. so thx to this formula ill be able to calculate final damage with "global('Damage') - global('DamageRessistance%') = global('DamageFinal')

    so on example 100dmg - 90% = 90

    em i correct? can i use such a formula?

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