How to form formulas

» Wed Nov 24, 2010 3:18 pm

thats wicked.
and it almost works. and i dont know why.

the problem is, last frame suppose to be 100% ShieldEnergy only, just the first frame 0% should be displayed only when ShieldsCurrent hits 0%. with this the last frame 100% is for some reason never played, or should i say - it is but if ShieldCurrent is about 100% (100,000001% for example).

so anyway, two questions:
why my method doesnt work and why your does.
also - what the heck is int expression??? i never seen that before on both expresions and system expresions pages on wiki.

and well... many my previous issues are left unasweared

[quote:3th6hoph]That's because of rounding errors - floating point numbers like 1.2 can't be counted on to be calculated exactly. It's a limitation of processors. If you want exact numbers, stick to integers (whole numbers without decimals like 1).[/quote:3th6hoph]

wow. everyday i learn something new. never knew about such thing. how weird is that O.o like - it can easly count 2 + 2 but have troubles with 0,2 + 0,2?
B
29
S
8
G
7
Posts: 643
Reputation: 6,482

» Wed Nov 24, 2010 4:22 pm

[quote="irbis":1yoaenlx]and well... many my previous issues are left unasweared [/quote:1yoaenlx]
Yes, they are, but isn't it much better to work on only one problem until it is solved, then go on to the next, instead of getting information overkill?

[quote="irbis":1yoaenlx]wow. everyday i learn something new. never knew about such thing. how weird is that simitation O.o like - it can easly count 2 + 2 but have troubles with 0,2 + 0,2?[/quote:1yoaenlx]
It can, but we the bad, mean humans limitate it. We only give him a limited number of bits. But with a floating point number there are occasions where those bits are not enough to exactly represent the number, and so the processor jumps to the nearest possible representation.

[quote="irbis":1yoaenlx]also - what the heck is int expression??? i never seen that before on both expresions and system expresions pages on wiki.[/quote:1yoaenlx]
[url:1yoaenlx]http://sourceforge.net/apps/mediawiki/construct/index.php?title=System_Expressions[/url:1yoaenlx]
You will find it under part 9: System
It converts a string or a float to an integer by rounding down.

[quote="irbis":1yoaenlx]the problem is, last frame suppose to be 100% ShieldEnergy only, just the first frame 0% should be displayed only when ShieldsCurrent hits 0%. with this the last frame 100% is for some reason never played, or should i say - it is but if ShieldCurrent is about 100% (100,000001% for example).[/quote:1yoaenlx]
The formula I wrote down is designed to show the shield status 100% only, if EnergyCurrent matches exactly EnergyTotal. On the other hand it displays the 0% frame also up until a certain amount (when using 11 frames everything below 10%)
If you want to tweak its behavior, just replace 'int' by 'round' or 'ceil'. Ceil rounds up to the next integer, and round rounds to the nearest integer [=> round(1.49) = 1, round(1.5) = 2]
If you use 'ceil' instead of 'int', then the 0% frame is only shown, if EnergyCurrent is exactly 0, whereas the 100% frame will be shown for every value above 90%.

[quote="irbis":1yoaenlx]why my method doesnt work and why your does.[/quote:1yoaenlx]
Just because I have a small lead over you in programming. Just keep on doing and you will solve such problems by yourself with ease. Promised.
B
24
S
8
G
10
Posts: 1,822
Reputation: 8,291

» Wed Nov 24, 2010 5:00 pm

[quote:1nsm11e8]
Yes, they are, but isn't it much better to work on only one problem until it is solved, then go on to the next, instead of getting information overkill? [/quote:1nsm11e8]

hmm. i need to agree with you but not entirely. you see my values system is all based on "set" event. for example imagine 100 shields types all called with "call function" event. and within that event the changes made by shields switching are made by "set var" event.

now imagine later when ill type all that engines, shields, weapons, reactors ect stats and ill find out that to have a buff/boost/bonus thing i must use something else then "set var" event. and now 2-3 days spent on rewriting all the "call functions".
its not like i want to do everything at once, its just i am a well planer aka i always try to met an dead end and be forced to go allll the way baaack.
thats why i want to know that before ill reach the "point of no return".
here, today i would propably use few extra variables to get the total value. like total value = valueReactor + valueBonus1 + valueUpgrade1 + valueAllYourBaseBelongToUs. but i would need to reserve a space for such variable. hmmm thinking of it... maybe ill just make that emergency variable after all? so when i change the TotalValue count so all the totalValue scatered around "Call Functions" be get auto-fixed.

[quote:1nsm11e8]It converts a string or a float to an integer by rounding down.[/quote:1nsm11e8]
string = text and float = ?
but... oh man. this might be beyond my capabilities. thats sound like chinese to me. its like saying it converts Er'Zuhz or a De'ruhn to an Elhe'lion by rounding down (thats dwarfish btw).
dont get me wrong, i am not jumping at you. i just look down, with pity, at my lack of understanding asking myself that horrible question - em i really sure i want to make a game with so less near to nothing programing knowledge. at this point i cant see how i am supposed to finish my game without some 2nd dev helping me out constantly(that wasnt any kind of suggestion, just my growing depresion).

[quote:1nsm11e8]The formula I wrote down is designed to show the shield status 100% only, if EnergyCurrent matches exactly EnergyTotal. On the other hand it displays the 0% frame also up until a certain amount (when using 11 frames everything below 10%)
If you want to tweak its behavior, just replace 'int' by 'round' or 'ceil'. Ceil rounds up to the next integer, and round rounds to the nearest integer [=> round(1.49) = 1, round(1.5) = 2]
If you use 'ceil' instead of 'int', then the 0% frame is only shown, if EnergyCurrent is exactly 0, whereas the 100% frame will be shown for every value above 90%.[/quote:1nsm11e8]

umm, so what? hold on. so okey umm and what if i want the opposite? i mean to have 0% be drawn when value is 0-9%? (+/-) or both? like 0% only when 0% and 100% only when 100%?
i am so sorry Tulamide, you must be feeling like talking to a rock

[quote:1nsm11e8]Just because I have a [size=200:1nsm11e8]HUGE[/size:1nsm11e8] lead over you in programming. Just keep on doing and you will solve such problems by yourself with ease. Promised.[/quote:1nsm11e8]
there, fixed. and i am more interested "why" technicaly my doesnt work.
like - all the ranges are being set, are conditions are being met. but it still doesnt aint working.
100% = show frame 11 (100%)
90-99% show frame 10 (90%)
80-89% show frame 9 (80%)
and so on. i dont understand why the engine cant get it and is either stuck on 1st frame or the 11th totaly ignoring everything betwen. and i am asking also because - not always the % splits we'll be the same. imagine a situation when i would want/need 10% frame be drawn on 20%, 20% be drawn at 60% and 30% be drawn on 90%. thats 3 diffrent jumps and the splits arent equal. with my method (if it would be working that is) i can easly adjuct any range(s) how i please when with your (even if its working) i am stuck with equal pieces.
and well, in most case i am uncertain will it work or not. but in this case was was 100% sure this will work. the rain started falling, ive opened my umbrella but my head still gets wet. i want to know why. where are the holes in the umbrella and how can i fix them.

EDIT:
oh great, it apears i cant define Variable with a sum of variables. like variable 1 = variable a + variable b. at least not from variable manager. my only idea is to set a "always" event defining that var. shame the variable manager doesnt recognise expressions though.
B
29
S
8
G
7
Posts: 643
Reputation: 6,482

» Wed Nov 24, 2010 6:53 pm

Lets look at this in a more simplified way.
If your max shield hp is 1000, and you have 10 different states, you can use that as a percentage.
>always
->sprite set frame to int(shields('health')/100)

Note:
Frame 0 is not possible, but the system will use the closest to it frame 1.

[url:3oaz7usp]http://dl.dropbox.com/u/666516/framepercent.cap[/url:3oaz7usp]

And while your looking at the system expressions take a look at lerp.
int(lerp(1,10, Sprite.Value('hp')/1000))
B
179
S
50
G
207
Posts: 8,719
Reputation: 128,306

» Wed Nov 24, 2010 7:02 pm

[quote:3u0a6okv]->sprite set frame to int(shields('health')/100)[/quote:3u0a6okv]

hold on, what do you mean by shields nad health?
i mean which is Total and which is Current? and do i need to set it for every state or like tulamide?

sorry. i still dont quit get what int expression really is. but this is more of english language problem rather then me being math-handycaped.
B
29
S
8
G
7
Posts: 643
Reputation: 6,482

» Wed Nov 24, 2010 7:19 pm

Correct me if i'm being dumb :

[quote:1ut1a92i]int(value)
Convert the given string or float to an integer.[/quote:1ut1a92i]

It means you can convert the text "3" to the number 3.

Or round the Float 3,2 to the Integer 3. (I think Tulamide said it is rounded down).

Etc...

You cannot convert text like 'blah blah" into a number with int. Actually, I wonder what int("blah blah") would return...
B
4
S
1
G
2
Posts: 91
Reputation: 1,057

» Wed Nov 24, 2010 7:26 pm

Yeah^
Int() just means that you want to use an integer, or whole number.
Not 0.5, 1.98988, but 1, 2, 3....
B
179
S
50
G
207
Posts: 8,719
Reputation: 128,306

» Wed Nov 24, 2010 7:43 pm

Btw, is there a difference between floor(3.2654) and int(3.2654) ?
B
4
S
1
G
2
Posts: 91
Reputation: 1,057

» Wed Nov 24, 2010 7:52 pm

Actually, it's a bit more.

numbers are rounded down to the next integer:
int(3.2) = 3
int(4) = 4
int(5.892) = 5

strings will be searched for numeric values at the beginning of the string, and the resulting number then rounded down to the next integer:
int("20") = 20
int("43.342") = 43
int("51abcdefg") = 51
int("51.56abcdefg") = 51
...
and ... int("blah blah") = 0

[quote="prawnsushi":udko19ii]Btw, is there a difference between floor(3.2654) and int(3.2654) ?[/quote:udko19ii]
I can't really see one, because floor works exactly the same than int (edit: forgot a word) even on strings...

[quote="newt":udko19ii]Lets look at this in a more simplified way.
If your max shield hp is 1000, and you have 10 different states, you can use that as a percentage.
>always
->sprite set frame to int(shields('health')/100)

Note:
Frame 0 is not possible, but the system will use the closest to it frame 1.

[url:udko19ii]http://dl.dropbox.com/u/666516/framepercent.cap[/url:udko19ii]

And while your looking at the system expressions take a look at lerp.
int(lerp(1,10, Sprite.Value('hp')/1000))[/quote:udko19ii]
This is confusing more than helping. Please have a look at my long post about it. There are two variables that are related to each other and influence each other. Also, my expression never reaches frame 0, I think it is a better way to make sure you don't get unwanted values instead of hoping that Construct will catch the error.
B
24
S
8
G
10
Posts: 1,822
Reputation: 8,291

» Wed Nov 24, 2010 8:17 pm

oh! so its just another variation of "round" expresion? O.o

so... i can use my method but i just need to add round...?

i just dont see whats wrong with my method (aside from the obvious - that it isnt working lol).
i mean - why? i am just like a guy who was drinking coffee and sudenly his coffee mug explode.
i am like - What The Hell?

also... Tulamide. for some reason frame 11 (graphical 100%) is never shown. the value must get higher then 100% like 100,6% in order for it to be show. how can this be fixed? can it? i mean - i can live on never seeing totaly empty ShielBar but never seeing Maxed bar is rather depresing and anoying. this is mostly because of that weird XX.0989987% result i am getting from the proccesor - i know. hey is there a way command to round down or up (or something) variable? the only event options i know are add substract and compare. otherwise i will be forced to follow Arima advice and pass on 0.XX values aka adjuct the whole points system by adding two more zeros to any value (so 0.01 will be now 1). but thats hell of a job and will turn any numbers into massive values (weakest game shield being 10000 instead of 100)

and well, i still dont know any method of capping a value. beside the obvious IF ShieldsCurrent is greater then ShieldsTotal substract -0.01.
[quote:t20jw1o1]
This is confusing more than helping.
[/quote:t20jw1o1]
totaly agree no offence of course. i just think i need to "level up" few times and ill be able to get hold on this.

anyway. thank you VERY KINDLY. all of you. this is an extreme convo and i learn alot.
in fact, just using/learning Construct and talking with you guys is more brain-stimulating then 5 years of my high-school had been.

PS:
and please note that i am NOT using you as my freeware teechers who are just waiting for me to whistle to come runing in lust of serving my needs. i respect you, you time and your imput. no one pays you for what you do, and i am aware of this.
but laso think how constructive and informative this thread is for any newbie like me who maybe have similiar problems.
B
29
S
8
G
7
Posts: 643
Reputation: 6,482

PreviousNext