intfiction.org

The Interactive Fiction Community Forum
It is currently Fri Feb 22, 2019 12:18 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Out Of temp variables?
PostPosted: Sat Mar 30, 2013 12:36 am 
Offline

Joined: Sun Feb 10, 2013 11:44 pm
Posts: 76
This was a question about how to make a command and pass it to another character, but I ran into another more pressing problems...

I can't seem to write anymore of my parser because Inform is telling me I ran out of temporary variables... (15?)
How is that even a thing?
How did I declare temp variables, they shouldn't be disposable at all, in fact all of them are important.
Is there some kind of declaration I should be using them to let inform know that they are not temp?


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Mar 30, 2013 1:40 am 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5921
The Z-machine is limited to 15 local variables per function. This is a hard limit and you can't do anything about it. You could re-declare some of them as global variables ("... a foo that varies"). That's probably the easiest way to proceed if you really want to maintain Z-machine compatibility. But I don't think that's going to be possible, from what you've been saying.

In Glulx the compiler defaults to a limit of 32 local variables, but you can increase this by saying "Use MAX_LOCAL_VARIABLES of 64" or whatever.

(If you're already in Glulx, then something else is going on and we'll have to investigate further.)


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Mar 30, 2013 5:42 am 
Offline

Joined: Sun Feb 24, 2013 3:54 pm
Posts: 6
halkun wrote:
How did I declare temp variables, they shouldn't be disposable at all, in fact all of them are important.


Temporary (i.e. local) variables are variables declared using "let". As zarf pointed out, global variables are declared using "is" combined with "that varies" if you want them to be mutable (which local variables always are, but globals aren't without that modifier).


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Mar 30, 2013 5:44 am 
Offline

Joined: Thu Oct 22, 2009 4:31 pm
Posts: 1309
Doesn't Inform 7 have a hard limit of 20 locals? So extending via glulx won't help...


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Mar 30, 2013 10:35 am 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5921
Does it? I looked for a bug report, on the theory that somebody would have run into this before, but I didn't see one.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Mar 30, 2013 10:51 am 
Offline

Joined: Thu Oct 22, 2009 4:31 pm
Posts: 1309
I think there have been multiple discussions of it here (@ intfiction) over the years. But I see that it's actually a limit of 15 temps, enforced by the I7 compiler regardless of whether you're compiling to Glulx or Z-code. Here's the message I just triggered in a Glulx game:

Inform 7 wrote:
You wrote 'end repeat' : but there are too many temporarily-named values in this phrase, which may be a sign that it is complicated enough to need breaking up into smaller phrases making use of each other. For reasons to do with the construction of IF story files, there can never be more than 15 temporary values at a time, and that has to include both values created in the declaration of a phrase (e.g. the 'N' in 'To deduct (N - a number) points: ...', or the 'watcher' in 'Instead of taking something in the presence of a man (called the watcher): ...'), and also values created with 'let' or 'repeat' (each 'repeat' loop claiming two such values) - not to mention one or two values occasionally needed to work with Tables. Because of all this, it's best to keep the complexity to a minimum within any single phrase.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Mar 30, 2013 12:13 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5921
Harrumph. Well, that error message is technically out of date, at least. I will file something.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Mar 30, 2013 12:50 pm 
Offline

Joined: Sat Jan 23, 2010 4:56 pm
Posts: 5921
Filed http://inform7.com/mantis/view.php?id=1092 .

In the meantime, I repeat my suggestion of using global variables instead of local ones. (This is in fact what the core I7 parser does, since that code dates back to Z-machine days.)


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Mar 30, 2013 6:10 pm 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 2600
Just be careful with using globals in phrases or rules that call themselves, because they will share them. For recursive code local variables are essential because each phrase gets its own ones and doesn't share them.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Mar 30, 2013 7:50 pm 
Offline

Joined: Sun Feb 10, 2013 11:44 pm
Posts: 76
Ok, so I'm going to kill two birds with one stone.

1) Now that I know a difference, I'm making my variables global that were supposed to be in the first place.
2) I'm only making indexed text if it actually needs to be indexed

However, it seems that I need to make all my text indexed if I'm going to me placing them in a table, but the examples in the manual say otherwise.

here's the error:
Quote:
Problem. In the sentence 'Let the japanese name be the jname corresponding to the ename of english name in the table of names' , you seem to be looking up a corresponding entry in a table: but it's fruitless to go looking for an indexed text in a column where each entry contains a text.


The Japanese name (Which is now non-temp) is type "text" and the table columns (jname and ename) are also now only text. So I have type agreement, but in needs to be indexed for the system to look though it?


=== EDIT ===
Found it, (I think) as an experiment I made "English name" some text and now I get
Quote:
In the line 'now the english name is the unpunctuated word number 1 in player's command' , you seem to be asking me to put an indexed text into a text, which can't safely be done.


So I actually need that indexed as I took it from the player's command and can't cast into another type. (demote?)


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group