Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 "Illegal get item" error.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
skingston




PostPosted: Mon Jun 03, 2013 3:55 pm   Post subject: "Illegal get item" error.

What is it you are trying to achieve?
I am trying to load a euchre deck of cards from a text file into an array of records - "cards"


What is the problem you are having?
When I compile and run the program, I get the error message "Illegal Get Item"


Describe what you have tried to solve this problem
I'm not sure where to start


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here is the code:

Turing:


% defines a type of variable to be used for the deck of cards
type card :
    record
        rank : char
        suit : int
        trump : boolean
    end record

% global deck of cards for the game
var deck : array 1 .. 24 of card

% loads an unshuffled Euchre deck from a file
proc loadDeck (cards : array 1 .. 24 of card)
    var file : int

    open : file, "deck.txt", get
    if file > 0 then
        for i : 1 .. 24
            get : file, cards (i).rank  % Illegal get item here
            get : file, cards (i).suit  % and here
        end for
        close : file
    else
        put Error.LastMsg
    end if
end loadDeck



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Mon Jun 03, 2013 4:05 pm   Post subject: RE:"Illegal get item" error.

That error message is incredibly unhelpful (Turing's fault, not yours).

The problem is that you have declared the cards argument without the var keyword.

If you look at http://compsci.ca/holtsoft/doc/procedure.html , you can see that parameter declarations have a form described at http://compsci.ca/holtsoft/doc/paramdeclaration.html . The optional [ var ] has this documentation:

Turing Help wrote:
Parameters to a procedure may be declared using var, which means that the parameter can be changed inside the procedure.


Unfortunately Turing is pretty awful at error messages (compared to modern languages, anyway). It should tell you that you can't change a constant (not variable) object, but instead you get that unhelpful error message.
evildaddy911




PostPosted: Mon Jun 03, 2013 4:09 pm   Post subject: RE:"Illegal get item" error.

mostl likely you are attempting to read past the end of the file. you are trying to read 24x2 items. make sure that
A) you have 48 items in the file and
B) they all are separated by a single space or the next item is on a new line.
for example (reading "_" as a space):
ok file:
code:

9_1_10_1_J_1_
Q_1_K_1

unreadable file:
code:

9__1_10_1_J1

Q_1_
K_1

things wrong with this file:
1) between the 9 and 1 there is a double space, causing the program to read the second item as " 1"
2) no space between J and 1. program will read "J1" as a single item
3) empty line: the second newline will be read as an item
4) [space][newline] will cause the program to think that the next item is "[newline]K"

Also, if you are having I/O problems, then usually it would be a good idea to give us the file that you are having troubles with along with the code

EDIT: sorry, I was busy posting and didn't see your post first. That is most likely the problem, although you should check and make sure your file will be read the way you intend it too
skingston




PostPosted: Mon Jun 03, 2013 4:36 pm   Post subject: Re: RE:"Illegal get item" error.

DemonWasp @ Mon Jun 03, 2013 4:05 pm wrote:
That error message is incredibly unhelpful (Turing's fault, not yours).

The problem is that you have declared the cards argument without the var keyword.

If you look at http://compsci.ca/holtsoft/doc/procedure.html , you can see that parameter declarations have a form described at http://compsci.ca/holtsoft/doc/paramdeclaration.html . The optional [ var ] has this documentation:

Turing Help wrote:
Parameters to a procedure may be declared using var, which means that the parameter can be changed inside the procedure.


Unfortunately Turing is pretty awful at error messages (compared to modern languages, anyway). It should tell you that you can't change a constant (not variable) object, but instead you get that unhelpful error message.


Thank you sooooo much! The 'var' keyword was all I needed.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: