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

Username:   Password: 
 RegisterRegister   
 "Compile Time Expression Expected"
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aerihk




PostPosted: Thu Oct 02, 2014 10:39 pm   Post subject: "Compile Time Expression Expected"

What is it you are trying to achieve?
I'm making a code cracking game, I think based off a game called Mastermind. It's been a long time. Anyways, you put in a number code, and the computer guesses. For each digit, it will get a response whether that number does not occur in the code, occurs at least once, but not in that position, or occurs in that position. It then uses this information to keep guessing until it gets it. In the original (physical) game, the code is made using 4 positions and 6 colours. I made that version easily, just changing colours to numbers. Now I'm trying to let the user choose the length of the code and the range of numbers that can be used.


What is the problem you are having?
I use the variables for the number range in the array variables, but it keeps saying "Compile Time Expression Expected". As I understand, this means I'm trying to call variables before I've set them, but I can't see a way it couldn't get to the place they're set. I made all my user input number variables strings so the program won't crash if they put something that's not a number. Then I check the length and ords to make sure it only uses numbers. If not, it just runs a loop so they have to try inputting again. If it works, it sets it to a new variable as an integer.


Describe what you have tried to solve this problem
I tried restating
ndig1 := strint (dig1)
ndig2 := strint (dig2)
at the note line after the loops. The errors are in the array variables shortly after that line.


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


Please specify what version of Turing you are using
4.1.1



v2.t
 Description:

Download
 Filename:  v2.t
 Filesize:  4.84 KB
 Downloaded:  167 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Oct 03, 2014 1:02 am   Post subject: Re: "Compile Time Expression Expected"

Aerihk @ Thu Oct 02, 2014 10:39 pm wrote:
it keeps saying "Compile Time Expression Expected". As I understand, this means I'm trying to call variables before I've set them

Not quite. It's expecting to be able to determine the value at compile time -- that is, at the time the program is build (before it's even run).

If you are looking to change the size of arrays that you use, then in Turing you need to use flexible arrays. There are some examples at http://compsci.ca/v3/viewtopic.php?t=14333
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Aerihk




PostPosted: Sat Oct 04, 2014 11:29 am   Post subject: Re: "Compile Time Expression Expected"

Okay, so it seems the issue is that I can't use a variable for the lower bound? I declared their (temporary) values all at the beginning where the variables are declared, and it's still not working Neutral
Tony




PostPosted: Sat Oct 04, 2014 1:59 pm   Post subject: RE:"Compile Time Expression Expected"

example code and error?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Aerihk




PostPosted: Sat Oct 04, 2014 2:18 pm   Post subject: Re: "Compile Time Expression Expected"

Same error. Code attached.


v2.1.t
 Description:

Download
 Filename:  v2.1.t
 Filesize:  4.97 KB
 Downloaded:  174 Time(s)

Tony




PostPosted: Sat Oct 04, 2014 2:40 pm   Post subject: RE:"Compile Time Expression Expected"

That's more code then necessary -- ideally you want to identify the smallest set of code that still demos the error. In this case it could be 2~3 lines.

The error suggests that you can't use a variable. You might be able to use a constant value instead.

Fundamentally, arrays are about having a continuous block of uniform elements -- array index is an offset from the beginning. You want to be thinking in terms of "what is the 2nd element". Having ranges like 100..105 doesn't fit that narrative.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: