Mode7 - (Solved)

Started by Dualnames, Sun 05/06/2011 19:03:07

Previous topic - Next topic

Calin Leafshade


monkey0506

You're all being ridiculously unhelpful. Dualnames raises a very valid point. Indentation, like any type of spacing in code other than between identifiers and keywords, is completely pointless. Here's a corrected version of the code for you Dual:

Code: ags
int ax,ox,fxx=25,fyy=0,fww,sections=20,d=20,ad;DynamicSprite*scale,res,parts[];DrawingSurface*bg,fx;float rw=5.0,rh=1.0;function room_Load(){bg=Room.GetDrawingSurfaceForBackground();object[0].Clickable=false;parts=new DynamicSprite[sections];}function room_RepExec(){if(ax>Room.Height-240){ax=Room.Height-240;}while(ad!=sections){int sze=(240/sections);float ratew=rw/IntToFloat(sections);float rateh=rh/IntToFloat(sections);scale=DynamicSprite.CreateFromDrawingSurface(bg,0,ax,320,240);parts[ad]=scale;parts[
ad].Crop(0,(sze*ad),320,sze);parts[ad].Resize(parts[ad].Width-((sections-ad)*FloatToInt(ratew)),parts[ad].Height-((sections-ad)*FloatToInt(rateh)));fx=res.GetDrawingSurface();if(ad>0){fww=(parts[ad].Width-parts[ad-1].Width)/2;}fx.DrawImage(fxx-fww,fyy+parts[ad].Height-1,parts[ad].Graphic);fyy=fyy+parts[ad].Height-1;fxx=fxx-fww;ad++;}ad=0;fx.Release();object[0].Graphic=res.Graphic;object[0].SetPosition(0,240);}function on_key_press(int keycode){if(keycode==eKeyUpArrow)ax+=d;if(keycode==eKeyDownArrow)
ax-=d;}


Unfortunately stupid AGS makes you have lines only 500 characters long so I had to split it to three lines for it to compile, but this is the prettiest code ever, and anybody who disagrees is a douchebag faggot who can screw off and die. Keep up the amazing work Dualnames.

You know, what really pisses me off is when people have a script that only has like less than 200 characters but spans across like 150 lines!! WTF?!? KEEP YOUR CODE CLEAN PEOPLE! KEEP IT ALL ON ONE LINE WITH NO SPACES UNLESS NECESSARY!!!

Khris

LOL, don't listen to monkey!!!111

I maded you the prettiestest code:

Code: ags
int
ax
,
ox
,
fxx
=
25
,
fyy
=
0
,
fww
,
sections
=
20
,
d
=
20
,
ad
;
DynamicSprite
*
scale
,
res
,
parts[
]
;
DrawingSurface
*
bg
,
fx
;
float
rw
=
5.0
,
rh
=
1.0
;

function
room_Load
(
)
{
bg
=
Room.GetDrawingSurfaceForBackground
(
)
;
object[
0
].Clickable
=
false
;
parts
=
new
DynamicSprite[
sections
]
;
}

function
room_RepExec
(
) 
{

res
=
DynamicSprite.Create
(
320
,
240
)
;

if
(
ax
>
Room.Height
-
240
)
ax
=
Room.Height
-
240
;
while
(
ad
!=
sections
)
{
int
sze
=
(
240
/
sections
)
;  
float
ratew
=
rw
/
IntToFloat(
sections
)
;
float
rateh
=
rh
/
IntToFloat(
sections
);
scale
=
DynamicSprite.CreateFromDrawingSurface
(
bg
,
0
,
ax
,
320
,
240
)
;
parts[
ad
]
=
scale;
parts[
ad
].Crop
(
0
,
(
sze
*
ad
)
,
320
,
sze
);
parts[
ad
].Resize
(
parts[
ad
].Width
-
(
(
sections
-
ad
)
*
FloatToInt
(
ratew
)
)
,
parts[
ad
].Height
-
(
(
sections
-
ad
)
*
FloatToInt
(
rateh
)
)
)
;
fx
=
res.GetDrawingSurface
(
)
;
if 
(
ad
>
0
)
fww
=
(
parts[
ad
].Width
-
parts[
ad
-
1
].Width
)
/
2
;
fx.DrawImage
(
fxx
-
fww
,
fyy
+
parts[
ad
].Height
-
1
, 
parts[
ad
].Graphic
)
;
fyy
=
fyy
+
parts[
ad
].Height
-
1
;
fxx
=
fxx
-
fww
;
ad++
;
}
ad
=
0
;
fx.Release
(
)
;
object[
0
].Graphic
=
res.Graphic
;
object[
0
].SetPosition
(
0
,
240
)
;
}

void
on_key_press
(
eKeyCode
keycode
)
{
if 
(
keycode
==
eKeyUpArrow
)
ax
+=
d
;
if 
(
keycode
==
eKeyDownArrow
)
ax
-=
d
;
}

LimpingFish

You fucking maniacs! You've killed the forum formatting! I'm typing this in a message box that's half-way across the fucking screen!

I hate you all!

...

What's indentation, and why should I care?
Steam: LimpingFish
PSN: LFishRoller
XB: TheActualLimpingFish
Spotify: LimpingFish

monkey0506

Slightly less seriously (*gasp*), Dual, I'm sure you're aware, but I want to point something out regarding indentation. In AGScript, as with most programming languages, whitespace is completely ignored by the compiler/interpreter, except as a delimiter between keywords and/or data types and the identifier associated with the variable/function being declared, defined, or referenced. Beyond that, AGS doesn't give a leprechaun's left testicle about how much or little whitespace you choose to put in your scripts.

So why then do we do these horribly infuriating things like indentation? Because we, as humans, tend to think a bit differently than machines do. There's an entirely separate point to take into consideration here than just indentation, which is the brace/bracket depth of any given line of code. By that I mean how deeply nested within a function and any conditions or loops that a given statement may be.

For example, a global variable within a script is declared outside of any functions, conditions, or loops, so we could say that the following has a brace depth of 0 (zero):

Code: ags
int ax;


A variable that is local to a function could be said to have 1 or more as the brace depth, depending on the contents of the function:

Code: ags
function on_key_press(eKeyCode keycode)
{ // open brace, first level
  int var = 5; // brace depth: 1
  if (keycode == 65)
  { // open brace, second level
    int i = 0; // brace depth: 2
    while (i < var)
    { // open brace, third level
      i++; // brace depth: 3
    } // close brace, third level
    Display("%d", i); // brace depth: 2
  } // close brace, second level
  else Display("Pressed key %d (%c).", keycode, keycode); // brace depth: 1
} // close brace, first level


As you can see, in this "properly" indented example, the indentation level directly correlates to the brace depth. This means that the end-user can, at-a-glance, almost immediately tell the brace depth of any given command/statement. We've already gone over the fact that AGS doesn't care about this indentation one way or the other, but it's a tool you can use to help yourself, and others, more quickly determine how deeply nested a certain line of code is.

The alternative (or, one of many) would be to use something probably between my post and Khris'. There are many indentation styles that work the same as my code here, but the ultimate key is consistency. As long as your indentation within a single function is consistent, then the purpose can be maintained. However, if you opt out of using indentation whatsoever, then you lose these described benefits.

Unless you have some massive, dynamically updated table that tells you the brace depth for every given line, then I don't see how else you're even reading and writing your own code. Short of manually counting from the beginning of each function every time you need to edit or try and debug your code..which you have to recognize is less efficient than something that allows an at-a-glance approach to the same thing.

So, in short, do what's best by you, but if you're remotely serious about a request for help in these or any programming-related forums, please just understand that indentation could quite well be the deciding factor whether you get the help you need. ;)

Khris

Should we care about whether Dualnames wants our help or not at this point? {
  I don't think so.
  But if you do, {
    remember that he hasn't earned it yet.
    Humoring him encourages his obnoxious behavior.
  }
  If you don't, {
    I'm with you.
  }
}
We don't need to explain to him why indentation is beneficial, it's obvious.

Gilbert

 >:( STOP humiliating each other for their habits on formating. This is OT for this topic and pointless. I'll consider locking this or deleting posts if this continues.

abstauber

@Khris: your code doesn't work too for exactly the same error I'm experiencing. I can't believe that I've reformatted that code block  :=

@Duals: Look at this thread. Steve's code is pretty close to what you're trying to achieve.
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=42122.0

Dualnames

I wonder which is more ridiculous, really.

My refusal to indent the code, or your inability to get out of this topic and bother with something else.
Even more ridiculous is Snarky's comment. For a number of reasons.

I apologize for being a brain-dead idiot and asking for help. You're not required to tell me how much i should indent my code and why.
If you can't read the code, I apologize, don't help me. There's absolutely no need for retarded jokes.

Again, you've all proved how awesome you are. Thanks for all the great help, my problem is solved.

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk