| Blockland Forums > Modification Help |
| "String always evaluates to 0" and finding a ratio |
| (1/3) > >> |
| Crysist:
When ever I try to execute an add-on I made (for megashot and giving more stats about screen resolution) always gives this in the console when it checks: --- Code: ---Client checking Add-On: Client_Winshot Loading Add-On: Client_Winshot (CRC:-1582617125) Add-Ons/Client_Winshot/client.cs (13): string always evaluates to 0. Add-Ons/Client_Winshot/client.cs (13): string always evaluates to 0. Executing Add-Ons/Client_Winshot/client.cs. Add-Ons/Client_Winshot/client.cs (13): string always evaluates to 0. --- End code --- Heres the code --- Code: ---function setmegashot(%num) { if(%num<=8 && %num>=0.2) { $megashotScaleFactor = %num; %hres = getword($pref::Video::resolution,0); %vres = getword($pref::Video::resolution,1); %hr = mCeil(%hres - 0.5); %vr = mCeil(%vres - 0.5); echo("Megashot "@%num@" | "@%hr@" x "@%vr); %ratio = %hr/%vr; //%rat = getratio(%ratio); if(%rat=="") { %rat=%ratio; } echo("Aspect Ratio "@%rat); } else { echo("Invalid Value"); } } function getratio(%ratio) { for(%i=1;%i<45;%i++) { %raat = %ratio*%i; %rate = mCeil(%raat - 0.5); %diff = %raat - %rate; if(%diff <= 0.1) { return %rate@":"@%i; } } } function getres() { %hr = getword(1,$pref::Video::resolution); %vr = getword(2,$pref::Video::resolution); echo(%hr@" x "@%vr); %rat = %hr/%vr; echo("Aspect Ratio "@%rat); return %hr@" "@%vr; } --- End code --- I commented out the part where it calls getratio(//%rat = getratio(%ratio);) because I though that was what was causing the problem. If anyone could tell me what I am doing wrong and also tell me how to make getratio work, I would really appreciate it. What I'm trying to make getratio do is you give it a ratio over one (like 1.777... which is 16:9) for example and attempt to find 16:9. I don't know if there's a function to turn 1.33333:1 into 4:3, so I tried making one. |
| Chrono:
%rat == "" should be %rat $= "" |
| TripleNickels:
Crycigarette! :D ^ is correct btw edit: This is unforgivable. |
| Truce:
--- Quote from: Crysist on June 30, 2011, 06:36:45 PM ---What I'm trying to make getratio do is you give it a ratio over one (like 1.777... which is 16:9) for example and attempt to find 16:9. I don't know if there's a function to turn 1.33333:1 into 4:3, so I tried making one. --- End quote --- I'm not exactly sure what I did but this turns 1.333 into 4:3 and 1.777 into 16:9. --- Code: ---function getRatio(%width) { %multi = 2 / (mCeil(%width) - %width); return mFloatLength(%width * %multi,0) @ ":" @ mFloatLength(%multi,0); } --- End code --- |
| Nexus:
--- Quote from: Truce on July 06, 2011, 05:33:46 PM ---I'm not exactly sure what I did but this turns 1.333 into 4:3 and 1.777 into 16:9. --- Code: ---function getRatio(%width) { %multi = 2 / (mCeil(%width) - %width); return mFloatLength(%width * %multi,0) @ ":" @ mFloatLength(%multi,0); } --- End code --- --- End quote --- What if an integer troll makes the game divide by zero? I just tried 2.25 %multi = 2 / (3-2.25) = 2.666667 Ratio would return 6:2 good for approximating though, I suppose. |
| Navigation |
| Message Index |
| Next page |