Community

SCI Programming => SCI Community How To's & Tutorials => Topic started by: amirkle on December 10, 2018, 01:51:23 PM

Title: Inventory problem
Post by: amirkle on December 10, 2018, 01:51:23 PM
Hello friends. I've been working on my game for a year and a half now. It's been a slow process, 'cause I'm working solo, plus I have no background in programming, so it's like walking through a dark forest with a dying candle...  But i'm pulling through.

I came across a scary point today, though: after adding an inventory item to the inventory script, my game wouldn't load anymore. i get an error no. 5 (have no clue what it means). the game works fine if i delete the new inventory item, which makes me suspect i got too many items on my inventory list. problem is, i can't possibly make it to the end of the game without adding at least 10 more items. Got the story in my head and all, and i'm afraid I've come to a dead end. Let me say I DO have a lot of items on the Inv list, and that my scripts are badly written, the outcome of not coming from the programming world and not knowing any effective codes. I'm improvising as i go, and the game is pretty long already. I can actually smell the end, but without adding some more Inv items... probably can't be done.   please, any tips??
Title: Re: Inventory problem
Post by: Kawa on December 10, 2018, 02:42:07 PM
E_BAD_SELECTOR. Try running the game on a debug build (attached) so you can see the full error: "'%s' is not a selector for %s.".

Also, how many items is many?
Title: Re: Inventory problem
Post by: amirkle on December 10, 2018, 02:56:05 PM
E_BAD_SELECTOR. Try running the game on a debug build (attached) so you can see the full error: "'%s' is not a selector for %s.".

Also, how many items is many?

It works with as many as 38 Inv items. the 39th crashes the game...
can't run the file you sent for some reason.
Title: Re: Inventory problem
Post by: amirkle on December 10, 2018, 02:58:40 PM
also, after crashing, i get this message:

"Timed out trying to start debugging functionality. This requires a compatible template game." at the output box
Title: Re: Inventory problem
Post by: Kawa on December 10, 2018, 03:15:09 PM
I'd really appreciate if you could tell me more besides "can't run for some reason". I can't help you without such information.

Just to be sure, I dropped SCI.EXE into the folders for King's Quest 6, Larry 6, and Freddy Pharkas. Only Larry 6 refused to run outright because it uses the menu system. So that just makes me real curious as to what possible reasons we could be missing here.
Title: Re: Inventory problem
Post by: amirkle on December 10, 2018, 03:24:55 PM
well, when I try to open the file I get a message it can't run on my pc. When I try to open it as an administrator it says it can't find it..
Title: Re: Inventory problem
Post by: Kawa on December 10, 2018, 03:30:24 PM
It's a DOS program, like SIERRA.EXE is. You can't run those as-is. Rename SIERRA.EXE to anything else, then rename SCI.EXE to SIERRA.EXE and hit that run or debug button in SCI Companion.

Edit: looking at your screenshots again, also don't forget to put it in the same folder as your game.
Title: Re: Inventory problem
Post by: amirkle on December 10, 2018, 03:38:22 PM
ok, got it!

does this one mean anything to you?
Title: Re: Inventory problem
Post by: amirkle on December 10, 2018, 03:44:04 PM
ok, got it!

does this one mean anything to you?

I also get this one:
Title: Re: Inventory problem
Post by: Kawa on December 10, 2018, 04:01:03 PM
Huh. I did not expect that. As I begin writing this, I'm officially stumped. That does not look like a selector name... more like some weird-ass script error ends up trying to invoke a selector with that absurdly-high number.

Seriously? 31890? The highest selectors are #4096 through #4103, and even they stand alone! The highest regular non-system selector in Gabriel Knight 2 is #918. So that's pretty out there.

But wait, it gets better! In the source code for the interpreter, if GetSelectorName fails to load a selector name, it just returns the buffer it was given untouched, so "7c92" isn't even the selector number -- it's just whatever happened to be in the memory area that the routine showing this error (or the "oops" one in a regular build) happens to contain! So this is next to useless after all that effort to teach you the basics of retrocomputing, except to show that it's a (doubly?) invalid selector.


What's nice is that the second screenshot can theoretically be used to find out where the issue happens exactly. Given a copy of the script file containing templateInventory and a copy of its disassembly, one might be able to deduce more about the problem's cause and possibly a solution.

But I may have an easier solution for your problem regardless. Or a workaround at any rate. Codename Iceman has several separate inventory sets throughout the game, spanning 34 items in total¹. so you might want to consider not adding all 40-something items in one go.

Perhaps the most sturdy solution would be to bite the bullet and do what the oops error said: rethink your strategy and try taking a different approach to the situation. Do you really need that many items? After all, that error is addressed to the developer, not the player.



¹: what's particularly interesting is that LSL6 has 42 items in total and KQ6 a whopping 52.
Title: Re: Inventory problem
Post by: lskovlun on December 10, 2018, 04:28:01 PM
After all, that error is addressed to the developer, not the player.
Are you sure about that...? Developers would see the more specific error message. If not the player, the only people I can imagine the "Oops..." message would be addressed to are the beta testers; and I don't know what build they got. For all I know, it might include the debugger. Also, they changed the message. It was different in the very first SCI interpreters. "You have encountered an internal error" or some such.

Bonus info: I once put the "Oops..." message in a comment in something I was writing at work. Just as a comment, of course.
Title: Re: Inventory problem
Post by: troflip on December 10, 2018, 05:09:36 PM
Doesn't the debug build of the interpreter have stack trace functionality? What's the stack trace? Should be an easy way to narrow down what's causing the problem.

Kawa's suggestion that something bad happened which resulted in trying to call an object with a ridiculous selector seems reasonable. As for what the root cause of *that* would be, my random guesses are:
- Some bug in SCI Companion's compiler
- Some kind of out of memory thing because you're using so much memory with inventory items (which are loaded all the time)
- Some bug in your new inventory item (pretty easily ruled out by removing other items and keeping your new item in)
Title: Re: Inventory problem
Post by: amirkle on December 10, 2018, 05:20:01 PM
Doesn't the debug build of the interpreter have stack trace functionality? What's the stack trace? Should be an easy way to narrow down what's causing the problem.

Kawa's suggestion that something bad happened which resulted in trying to call an object with a ridiculous selector seems reasonable. As for what the root cause of *that* would be, my random guesses are:
- Some bug in SCI Companion's compiler
- Some kind of out of memory thing because you're using so much memory with inventory items (which are loaded all the time)
- Some bug in your new inventory item (pretty easily ruled out by removing other items and keeping your new item in)

Yeah, I guess the problem has got to do with over-usage of memory.
wish there was a way to go around it, or to enlarge the possible memory usage. I guess i'll just have to figure out a way to cut on inventory items somehow and finish the game as long as i still have some memory to rely on...

unless you guys have any idea as to how to solve the issue otherwise?
Title: Re: Inventory problem
Post by: Kawa on December 10, 2018, 05:30:36 PM
unless you guys have any idea as to how to solve the issue otherwise?
Memory limits because all these items are loaded at all times?

Like I said, check out Codename Iceman:

Code: [Select]
;;; tahitiInv.sc, #371
;;; --------------------

(instance tahitiInv of Code
(properties)

(method (init)
(gInv add: Black_Book Change Key Earring)
)

(method (dispose)
(gInv delete: Black_Book Change Key Earring)
(DisposeScript 371)
)
)

(instance Black_Book of InvI
(properties
said '/book[<black,address,call]'
view {tahitiInv}
loop 1
value 1
name "Black Book"
)
)

(instance Change of InvI
(properties
said '/change,coin'
view {Black Book}
loop 2
value 1
)
)

(instance Key of InvI
(properties
said '/key'
view {Black Book}
loop 1
value 1
)
)

(instance Earring of InvI
(properties
said '/earring'
view 313
value 1
)
)

That's all the items you can use in Tahiti. Then there's #372 subInv.sc that defines another 15 items that you can only use while in the submarine and related areas. #819 preloadCode.sc shows that you gotta load the new and dispose the old, lest you get all 18 items for Tahiti and the submarine loaded at the same time.
Title: Re: Inventory problem
Post by: troflip on December 10, 2018, 05:33:29 PM
Find the root cause before concluding that the problem is your memory usage (speaking of... what IS your memory usage?). It actually seems really weird that you would run out of memory right at the game start if you add that one extra inventory item, but not if you play the game for a while with one less inventory item. Right?

Again,
- what's the stack trace when the crash occurs?
- have you established that it's the addition of one more inventory item that's causing the problem, instead of that *specific* inventory item?

So many easy things you can do to help root cause the problem.
Title: Re: Inventory problem
Post by: lskovlun on December 11, 2018, 05:12:15 PM
Find the root cause before concluding that the problem is your memory usage (speaking of... what IS your memory usage?). It actually seems really weird that you would run out of memory right at the game start if you add that one extra inventory item, but not if you play the game for a while with one less inventory item. Right?
Come to think of it, Kawa had symptoms of the same sort when trying to make a new template game. On the other hand, that task is fraught. But you never know.
Title: Re: Inventory problem
Post by: Kawa on December 11, 2018, 09:05:25 PM
I wasn't running out of memory. It was being Really Weird about language codes.
Title: Re: Inventory problem
Post by: lskovlun on December 12, 2018, 04:12:09 AM
I wasn't running out of memory. It was being Really Weird about language codes.
But it was still triggered by something to do with the inventory:
Quote
I give up. I try to remove all but one of the inventory items, game won't start
It's likely some sort of memory corruption that causes it, but I've no idea why.
Title: Re: Inventory problem
Post by: amirkle on December 12, 2018, 10:02:23 AM

- what's the stack trace when the crash occurs?
- have you established that it's the addition of one more inventory item that's causing the problem, instead of that *specific* inventory item?

So many easy things you can do to help root cause the problem.

It's very weird... it's not that one specific item that causes the problem. the game crashes the moment i got a 39th inventory item in my inventory script. it works fine with 38 items (potential items, cause the game wont start at all with a list of 39, even when none has been taken on game)

im very sorry for my ignorance, but what is the stack trace and where can i find it?

also, how do i see my memory usage?
Title: Re: Inventory problem
Post by: troflip on December 12, 2018, 02:31:12 PM
im very sorry for my ignorance, but what is the stack trace and where can i find it?

also, how do i see my memory usage?

If you press ? while in the debugger (when the game crashes when using the debug-enabled interpreter built by kawa), it should pop up a menu of commands. One of them should be 's', which will show the call stack (or the 'send' stack, which is almost the same).

There should be some commands to show memory information too.
Title: Re: Inventory problem
Post by: Kawa on December 12, 2018, 04:32:58 PM
If you press ? while in the debugger (when the game crashes when using the debug-enabled interpreter built by kawa), it should pop up a menu of commands.
Or it will crash because it can't load the debug help text, in which case:

q - quit

b - set breakpoint - object,method
B - set breakpoint - object,method (sticky)
<ctrl>B - clear sticky object,method breakpoint
n - set breakpoint - script,offset
N - set breakpoint - script,offset (sticky)
<ctrl>N - clear sticky script,offset breakpoint
R - break at the next return

C - clear all breakpoints and exit debug
D - exit debug
` - toggle debug

Enter - single step
Tab - step across send

a - inspect ID in accumulator
c - inspect current object
i - inspect object or memory
d - inspect hunk address

f - show free heap
s - show sends
r - show resource types
o - show objects in heap
O - show objects w/ addresses
S - show stack usage

g - edit global var
l - edit local var
f - edit frame var (temp var)

i - inspect selector
e - edit heap address or selector
t - trace heap address or selector
T - trace hunk address

c - display collection

left, right arrow
  - move address by 2 bytes
up, down arrow
  - move address by 16 bytes
pageup, pagedown
  - move address by 64 bytes

[ - move to next in doubly-
    linked list
] - move to previous in
    doubly-linked list
Title: Re: Inventory problem
Post by: amirkle on December 13, 2018, 03:47:42 AM
ok, that's the one. couldn't get the info regarding memory usage though, not by pressing "i" for memory indicator at least...

got any thoughts? does that stack trace tell you anything?
Title: Re: Inventory problem
Post by: Kawa on December 13, 2018, 05:25:55 AM
It still can't name the method...
Title: Re: Inventory problem
Post by: troflip on December 13, 2018, 12:53:05 PM
Maybe there are too many parameters in the send call when you're adding items? Send/self/super calls put a sequence of values on the stack, of the form:

Code: [Select]
selectorNumber numParams [param0-paramN] selectorNumber numParams [param0-paramN] ... totalNumberOfBytes

I'm guessing something is wrong somewhere in there and one of the parameters is being treated as a selector number (method call).

What does your templateInventory init method look like? More specifically, the self call when you add the items? What does the disassembly look like? (Script -> Disassemble).

Also, what's the size the size of the heap and script resources for this script? (script 15, I presume). Can you attach the script and heap resources to a post?