never mind

Started by alex, Tue 24/02/2009 15:51:29

Previous topic - Next topic

alex

Code: ags
[code][code][code]AGS Editor .NET (Build 3.1.2.81)
v3.1.2, February 2009

In GlobalScript.asc:

   

    if (mouse.Mode>0) mouse.Mode=mouse.Mode-1;
    else
    { [/code]

Should be:

   [/code]    if (mouse.Mode>0)
    {
      mouse.Mode=mouse.Mode-1;
    }
    else
    {  [/code]

If you want the conditional to work properly.

I'm still fairly new to AGS so I am not quite sure what will happen as a result of the broken conditional.  It looks to me like this is supposed to happen:

If you scroll up when the mouse mode is Walk, and the player does have an active inventory item, then set the mouse mode to the inventory item... Otherwise, if the player doesn't have an active inventory item, set the mouse mode to "talk".

This behavior is being ignored in the present version of the code I have thanks to that semicolon.  Was there a different reason for this?

Anyway it doesn't seem to be important but I thought I would point it out.

Gilbert

I don't quite understand your meaning. Did you mean that the results of the two ways of writting the codes give different results?

Their effects should be identical, as you don't really need to enclose the line of codes in {} braces if there is only one line of codes in each case of an 'if' clause.

Khris

This is a semi-colon: ;

As Gilbet pointed out, there's zero difference. Did you test the behavior before reporting this? Or did you just read through the script while being someone who is "still fairly new to AGS" and post the first thing that seemed odd to you?

I don't mean to be rude, but seriously...

alex

Hmm you're right.  I had assumed this was poorly coded (the practice I always use in C++ calls for {} regardless of whether I am using one line or not, for readability), and on top of that unfamiliarity with the engine meant I didn't know how to test for whatever error I assumed must be occurring.  Let's just say I was trying to be helpful and messed up.

paolo

Quote from: alex on Tue 24/02/2009 17:09:22
I had assumed this was poorly coded (the practice I always use in C++ calls for {} regardless of whether I am using one line or not, for readability) [snip]

Alternatively, if you are going for readability but don't want to bother with the braces because only one line follows the if, I would strongly advise putting the "if" statement and the statement that follows on separate lines.
Code: ags
if (long conditional goes here) do this;
do that;
is bad style, as, at first glance, it looks like it means "if (...) do that" when in fact it means "if (...) do this; then do that whether or not (...) was true ". One statement per line is good practice, unless you are writing a book and your publishers want to keep paper costs down.

Pumaman

Yeah, if I was to start AGS today, I'd make the script compiler require { } to avoid the confusion and mistakes that it can cause by not using them. But anyway, at least this way means it's the same as C#/C++/etc :P

alex

In either case, a really stupid post was a good way to introduce myself on the forums.

Sigh.

I'm in hospital with my wife looking after my premmy baby so I won't be around for a while anyway - maybe time enough for the dust to settle (fingers crossed)

SMF spam blocked by CleanTalk