Author Topic: String pain  (Read 102 times)

0 Members and 1 Guest are viewing this topic.

Offline gumby

String pain
« on: October 14, 2017, 11:12:07 AM »
The below code lives in a room script, in the doVerb method of a prop. I have a text resource that contains all of my noun names, resource 1 and in this case hard-coded to index position 35 (sword).  I've ripped everything out except for the code that I'm struggling with:

Code: [Select]
; On first invocation, prints  "The sword won't fit in the box". 
; On subsequent invocations, only prints "sword"

    (method (doVerb theVerb param2 &tmp [test1 50])
         (Printf "The %s won't fit in the box" (GetFarText 1 35))
    )

I tried this with the same results as above:
Code: [Select]
; On first invocation, prints  "The sword won't fit in the box". 
; On subsequent invocations, only prints "sword"

    (method (doVerb theVerb param2 &tmp [test1 50])
         (StrCpy @test1 (GetFarText 1 35))
         (Printf "The %s won't fit in the box" @test1)
    ) 
   
The only thing that does work is this:
Code: [Select]
; On every invocation, prints  "The sword won't fit in the box".

    (method (doVerb theVerb param2 &tmp [test1 50])
         (Printf "The %s won't fit in the box" (Format @test1 1 35))
    )   

Can someone help me understand what's going on here?  Seems like #1 & #2 should work fine, #3 sort of makes sense (I assume a pointer to @test1 is being returned from the Format call and the Printf statement is able to use it).
« Last Edit: October 14, 2017, 01:07:15 PM by gumby »


In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline lskovlun

Re: String pain
« Reply #1 on: October 14, 2017, 03:31:31 PM »
GetFarText and Format both require the address of a buffer workspace. In your first two snippets, no address is given, causing unpredictable behavior. Note that the address pointer is given as the first argument to Format, but as the last argument to GetFarText. The effects of omitting a parameter are subtly different.

http://sierrahelp.com/SCI/SCIStudio3Help/SCC/Kernel_GetFarText.html
http://sierrahelp.com/SCI/SCIStudio3Help/SCC/Kernel_Format.html


Offline gumby

Re: String pain
« Reply #2 on: October 14, 2017, 04:19:24 PM »
That was it, missing the buffer in the GetFarText call - thank you.  My trouble started because I have other code that omits the buffer as well (in a Prints call) but it never got inconsistent results.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition


SMF 2.0.11 | SMF © 2015, Simple Machines
Simple Audio Video Embedder

Page created in 0.098 seconds with 21 queries.