How to form formulas

For questions about using Classic.

Post » Fri Nov 19, 2010 10:06 pm

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"

[code:3co6gxlq]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.
ImageImageImageImage
B
26
S
7
G
7
Posts: 572
Reputation: 6,097

Post » Fri Nov 19, 2010 11:00 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Sat Nov 20, 2010 9:33 am

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 :)
ImageImageImageImage
B
26
S
7
G
7
Posts: 572
Reputation: 6,097

Post » Sat Nov 20, 2010 2:09 pm

Don't beat yourself up, you gotta learn it one way or another! :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Sun Nov 21, 2010 4:49 pm

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/
ImageImageImageImage
B
26
S
7
G
7
Posts: 572
Reputation: 6,097

Post » Sun Nov 21, 2010 5:05 pm

use apppath & "filename.extension"
example
[url:3lbif1o6]http://dl.dropbox.com/u/5811650/apppath.rar[/url:3lbif1o6]

Edit: oh, and the cap/exe and the file must be in the same folder
B
9
S
3
G
3
Posts: 366
Reputation: 2,301

Post » Sun Nov 21, 2010 5:26 pm

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
ImageImageImageImage
B
26
S
7
G
7
Posts: 572
Reputation: 6,097

Post » Sun Nov 21, 2010 7:36 pm

Try: AppPath & "Subfolder\filename.ext"
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Sun Nov 21, 2010 8:47 pm

[quote="Ashley":3srr8btz]Try: AppPath & "Subfolder\filename.ext"[/quote:3srr8btz]

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"

[code:3srr8btz]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
ImageImageImageImage
B
26
S
7
G
7
Posts: 572
Reputation: 6,097

Post » Sun Nov 21, 2010 10:41 pm

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
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 13 guests