[08 Apr 2007] Help with a logic problem

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
Dwayne

[08 Apr 2007] Help with a logic problem

Post by Dwayne »

Note: This is an archived post that was originally sent to the Hollywood mailing list on 08 Apr 2007 13:49:07 +1000

Hi,

I'm having some difficulty with a logic problem. I am trying to break a While loop from a function recursion by using one of two tests.

The first test works and is returning from the function recursion but the second test which is supposed to finish the while loop on the last iteration of the function recursion always seems to fail and I get file read errors because I am reading past the end of file.. I have the exact same issue if I try to check for EOF as the second check in the while loop which is why i am testing with variables instead.

The While statement is this

Code: Select all

While ((linetype <> 3) Or (((linetype=3) & (tag=1))=False)) 
To exit a normal iteration of the function linetype=3 and the while loop is finishing and the function is returning to the previous but on the last recursion of the function where I want it to exit before it reads the next line the values are:

linetype=3 and tag=1 But the While loop is coninuing??

Is my logic floored somewhere. I have tried using the binary operators | and & instead of Or and And with no success.

Ideally I would like to test for either linetype=3 or the EOF (File$) but this didn't work either..

Any help would be gratefully received.

PS. I am writing a script that will hopefully read in a Meedio configuration file and display screens based on their configuration. Meedio is a program on Windows that displays information much like Windows Media Center but is far more configurable and accessible than Windows Media Center and has hundreds of Plugins.. I don't intend on using the plugins simpy the screen layout config files so that I can present an easy to use menu system for accessing lots of different information such as a video library, music, games, weather etc..

Thought It would be cool to see a front end program to launch emulated games through Mame or UAE or even launch videos via Mplayer or DVPlayer.

Regards,

Dwayne
User avatar
airsoftsoftwair
Posts: 5832
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[09 Apr 2007] Re: Help with a logic problem

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 09 Apr 2007 12:42:26 +0200
The While statement is this

While ((linetype <> 3) Or (((linetype=3) & (tag=1))=False))

To exit a normal iteration of the function linetype=3 and the while loop is finishing and the function is returning to the previous but on the last recursion of the function where I want it to exit before it reads the next line the values are:

linetype=3 and tag=1 But the While loop is coninuing??
Well, the above loop won't quit when linetype=3. It will loop until linetype=3 AND tag=1. Linetype=3 is not enough to break this loop because you're using an Or condition which will be True until linetype=3 and tag=1.

If you want your loop to break on linetype=3 and (linetype=3 and tag=1) use

Code: Select all

While (linetype <> 3) Or (linetype<>3 And tag<>1)
But the tag of course doesn't make really sense in this case because linetype=3 is enough to break the loop.

Your logic seems somewhat flawed :)
Is my logic floored somewhere. I have tried using the binary operators | and & instead of Or and And with no success.
No, you will want to use the logical operators here. Don't use the binary And/Or in this case.
Ideally I would like to test for either linetype=3 or the EOF (File$) but this didn't work either..
Are you sure you're using Eof() correctly? It doesn't expect a file$ but a file id. Here's a small test. It will print the contents of the startup-sequence until Eof or LMB press.

Code: Select all

OpenFile(1, "s:startup-sequence", #MODE_READ)
While (IsLeftMouse() = False) And (Eof(1) = False)
	DebugPrint(ReadLine(1))
Wend
Dwayne

[10 Apr 2007] Re: Help with a logic problem

Post by Dwayne »

Note: This is an archived post that was originally sent to the Hollywood mailing list on 10 Apr 2007 19:47:56 +1000

Hello Andreas,

This still fails the test.

Here is the function so you can understand why I have both conditions being checked.

Code: Select all

Function p_ParseFile (file$, tag)
    Local ret={}
    Local linetype=0
    Local value$=""

    While (linetype<>3) Or ((linetype<>3) And (tag<>1))
        While (linetype <> 3)
            ret=p_ParseLine (TrimStr (ReadLine (file$), " ", False), linetype, tag)
            linetype=ret[0]
            Switch linetype
            Case 1:

            Case 2:
                linetype=0
            Case 3:
                p_DebugPrint (ret[2], tag, True, True)
            Case 4:
                /* p_DebugPrint (ret[2], tag, True, True) */
                tags[tag]=ret[2]
                p_ParseFile (file$, (tag+1))
                linetype=0
            Case 5:
                p_DebugPrint (ret[2], tag, False, True)
                p_AddTableEntry (ret[2], tag)
                linetype=0
            Case 6:
                value$=ret[2]
                /* p_DebugPrint (ret[2], tag, False, True) */
            Case 7:
                value$=value$ .. " " .. ret[2]
                /* p_DebugPrint (ret[2], tag, False, True) */
                linetype=6
            Case 8:
                value$=value$ .. " " .. ret[2]
                value$=p_SplitLine (value$, tag)
                p_DebugPrint (value$, tag, False, True)
                p_AddTableEntry (value$, tag)
                linetype=0
            EndSwitch
        Wend
    Wend
EndFunction 
The file that is being read has the following tags that get checked..

Code: Select all

<resources>
  <colors>
    <no-color a="0" r="0" g="0" b="0" />
    <white a="255" r="255" g="255" b="255" />
   </colors>
</resources>
With the function calling itself I found that it was neccessary to add an extra closing tag to the end of the file to avoid the end of file so I added </> to the end..

It seems that the While loop does work but it is not existing soon enough to the original iteration of the function..

Oh well.. for the time being I will have to modify the files..

I also seem to have difficulty printing [ brackets which appear in the config files I am reading.. but have no problem with " even though I don't use \ to format the output for the double quote.. This is only a concern when debugging the output and when I have completed testing I will re-use [ unless there are problems with adding this to a table even though they are in a string i.e.

Code: Select all

table["resources.fonts.main-font"]["shadow"]="[no-color]"
Would this be the best way to store these values.. I have been trying various ways of building tables and this appeared to be the best way to go.. I got lots of errors doing it other ways.. I originally attempted to use the examples and build the table but couldn't work out how to add to the table after an initialising..

ideally I would have liked to do this table {resources {colors {no-color {default=,$00000000, argb=$00000000, rgb=$000000}}}}

and add to the table other resources.. table {resources {fonts {main-font {shadow="[no-color]", size="18", type-face="Arial"}}}}

And then access them via SetFontColor (table.resources.colors.no-color.rgb)

But this doesn't seem to fit with how I thought the tables could be manipulated, but I am no expert..

I ended up butchering them and access them via

Code: Select all

SetFontColor (table["resrouces.colors.no-color"]["rgb"])
Not exactly ideal.. expecially when you need to know exactly where the table entries are since they are only referenced in the config files by no-color.. I get around this by having a second table called index which you can pass it the unique tag or identifier i.e. no-color and it would return the table entry.. i.e.

Code: Select all

SetFontColor (table [index["no-color"]]["rgb"])
Anyway this is becoming a long and probably tedious e-mail for you all.. but I am very interested in better ways of managing multi dimension tables..

Regards,

Dwayne
Locked