Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: alex on Tue 24/02/2009 15:51:29

Title: never mind
Post by: alex on Tue 24/02/2009 15:51:29
[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.
Title: Re: Cursor mode: Mouse wheel bug and fix
Post by: Gilbert on Tue 24/02/2009 15:58:47
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.
Title: Re: Cursor mode: Mouse wheel bug and fix
Post by: Khris on Tue 24/02/2009 16:36:44
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...
Title: Re: Cursor mode: Mouse wheel bug and fix
Post by: alex on Tue 24/02/2009 17:09:22
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.
Title: Re: Cursor mode: Mouse wheel bug and fix
Post by: paolo on Wed 25/02/2009 12:55:51
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. 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.
Title: Re: never mind
Post by: Pumaman on Wed 25/02/2009 18:56:35
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
Title: Re: never mind
Post by: alex on Tue 03/03/2009 04:59:51
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)