Community

SCI Programming => SCI Syntax Help => Topic started by: robbo007 on July 21, 2025, 06:52:25 AM

Title: Money, cash greenback
Post by: robbo007 on July 21, 2025, 06:52:25 AM
Hi guys,
I'm trying to work out the easiest way to implement money in my game. I have defined my "cash" Iitem in my main.sc:
Code: [Select]
(instance CASH of Iitem
   (properties
      said 'cash'
      description 108 ;Lots of cash
      owner 0
      view 233
      loop 0
      cel 0
      script 0
      name "Lot'o Cash"
   )
)

I'm not sure how to tackle the way to make it show the actual amount of cash ego has when viewing it via the inventory? Or to add/remove more cash to the inventory item?

Would I use something like:

Code: [Select]
(gEgo get: INV_CASH 1)To add 1 more $1 to it? and the same to remove it:
Code: [Select]
(gEgo put: INV_CASH -1)
Is this all controlled by a global value ?

Thanks,

Title: Re: Money, cash greenback
Post by: Kawa on July 21, 2025, 07:28:24 AM
Keep a global variable to track the exact amount of cash, yeah.

Assuming from the said property that this is SCI0, you can override the Cash item's showSelf to use a formatted print instead of a regular one to splice in the value of that global:

Code: [Select]
(instance Cash of Iitem
(properties
said 'cash'
owner 0
view 800
loop 0
cel 0
script 0
name "Cash"
)

(method (showSelf &tmp [buf 500])
; Substitute a text resource tuple at your leisure.
(Format @buf {Doesn't look like cash, but it is. $%d of it, even!} gCash)
(Print @buf #title objectName #icon view loop cel)
)
)

What you might want to do is either have a wallet that's always in your inventory and may be empty (LSL1), or have a procedure in script 0 to give or take money that, if you have the Cash item but the global goes <= 0 it takes away the item, or if it's > 0 and you don't have the item, gives it to you.
Title: Re: Money, cash greenback
Post by: robbo007 on August 13, 2025, 04:33:53 PM
Keep a global variable to track the exact amount of cash, yeah.

What you might want to do is either have a wallet that's always in your inventory and may be empty (LSL1), or have a procedure in script 0 to give or take money that, if you have the Cash item but the global goes <= 0 it takes away the item, or if it's > 0 and you don't have the item, gives it to you.

So I opted for the LSL1 approach on this with a global value of gLarryDollars

Code: [Select]
(instance WALLET of Iitem
(properties
said '/wallet'
description 105 ;You've had this baby since Leisure Suit Larry 1. It contain $%d in cash.
owner 0
view 231
loop 0
cel 0
script 0
name "Wallet"
)
(method (showSelf &tmp [buf 500])
(Format @buf 000 105 gLarryDollars)
(Print @buf #title objectName #icon view loop cel)
)
)

How do you get the parser to understand "look wallet" or "look at wallet"? without adding that to every room? Does it not pick up the Said from the syntax in the Iitem?
Title: Re: Money, cash greenback
Post by: Kawa on August 13, 2025, 04:48:52 PM
Quote
How do you get the parser to understand "look wallet" or "look at wallet"?
Any Said handling that applies anywhere goes in the main game object's handleEvent method.

To steal some framework from LSL3...
Code: [Select]
(method (handleEvent event)
  (super handleEvent event)
  (if (or (!= (event type) saidEvent) (event claimed)) (return))

  (cond
;.... other stuff...
    ((Said 'look>')
      (cond
        ((Said '/self')
          (Print "You look like shit lol")
        )
        ((Said '<at/wallet')
          (WALLET showSelf:)
        )
;.... other stuff...
      )
    )
  )
)

I don't even know anymore, it's too dang hot.
Title: Re: Money, cash greenback
Post by: robbo007 on August 14, 2025, 04:57:08 AM
ok thanks. So there is no way to include this with less code in the main.sc? If I have to add everything to the game object's HandleEvent method I'll create soo much code.

I see in LSL3 main.sc  decompiled by sluicebox all the items can be "look"'ed at once you have the item in inventory from any room. It seems to only be declared like this in the main.sc

Code: [Select]
(instance Penthouse_Key of Iitem
(properties
name {Penthouse Key}
said '/key'
owner 450
view 12
)
)

If I declare my item like that I can't look at it. It only works by going into the inventory and selecting it. I can't type "look wallet".

Code: [Select]
(instance WALLET of Iitem
(properties
said '/wallet'
description 105 ;You've had this baby since Leisure Suit Larry 1. It contain $%d in cash.
owner 0
view 231
loop 0
cel 0
script 0
name "Wallet"
)
(method (showSelf &tmp [buf 500])
(Format @buf 000 105 gLarryDollars)
(Print @buf #title objectName #icon view loop cel)
)
)
Title: Re: Money, cash greenback
Post by: Kawa on August 14, 2025, 05:13:31 AM
You can't look wallet without handling that input. That's what the handleEvent is for. You've seen the LSL3 code I referenced (well technically I referenced the original Al code, not sluice's), you know what I'm talking about.
Title: Re: Money, cash greenback
Post by: lskovlun on August 14, 2025, 07:54:16 PM
I am confused now. Don't the system classes handle this (using the saidMe mathod)?

To clarify, I see this in main.sc of LSL3 (in a cond block in handleEvent):
Code: [Select]
((Said 'look>')
(cond
...
((= temp2 (gInventory saidMe:))
                                                (if (temp2 ownedBy: gEgo)
                                                        (temp2 showSelf:)
                                                else
                                                        (Print 0 62) ; "You see nothing special."
                                                )
                                        )

Title: Re: Money, cash greenback
Post by: Doan Sephim on August 14, 2025, 09:57:58 PM
Yes, Iskovlun is correct. I use something similar in Betrayed Alliance.
Code: [Select]
(if (Said 'inv')
(gInv showSelf: gEgo)
)
(if (Said 'look>')
(cond
((= i (gInv saidMe:))
(if (i ownedBy: gEgo)
(i showSelf:)
else
(PrintDontHaveIt)
)
)
)
)
I'm using "i" instead of "temp2" but they're just variables declared in the the main script's handleEvent method, in my case:
Code: [Select]
(method (handleEvent pEvent inputNumber &tmp i)Kawa is correct that you don't need to overdo the item instances.
Title: Re: Money, cash greenback
Post by: robbo007 on August 15, 2025, 04:51:46 AM
Amazing thanks. That's what I needed. I did not see this in the LSL3 code. It must of slipped by me. Not being a programmer by trade the variables sometime evade my thought pattern.
Regards,
 
Title: Re: Money, cash greenback
Post by: robbo007 on August 18, 2025, 11:56:30 AM
sorry to prolong this simple syntax...

What's the best way to troubleshoot "Bad Said Sepc hit return to continue / 88 , 89 )" errors?

The "look wallet" seems to be working from a main.sc perspective. It shows the wallet from the inventory when ego has it, all good.  It's in some rooms I get "bad said spec errors" and it does not do this with all inventory items.

For example the inventory item wetsuit has no bad spec error:

Code: [Select]
(instance WETSUIT of Iitem
(properties
said '/wetsuit'
description 77 ;A wetsuit.
owner 0
view 203
loop 0
cel 0
script 0
name "Wetsuit"
)
)


Regards,
Title: Re: Money, cash greenback
Post by: Doan Sephim on August 19, 2025, 11:52:32 AM
If you're getting bad spec returns but only in certain rooms, that would suggest that you only have syntax errors in those specific rooms. I'd look for errors there.
Title: Re: Money, cash greenback
Post by: lskovlun on August 19, 2025, 01:47:50 PM
What's the best way to troubleshoot "Bad Said Sepc hit return to continue / 88 , 89 )" errors?
Those numbers look like they are word numbers. Try looking them up on the vocab screen in Companion. That'll tell you which spec is at fault (hopefully).
Title: Re: Money, cash greenback
Post by: robbo007 on August 20, 2025, 06:37:16 AM
What's the best way to troubleshoot "Bad Said Sepc hit return to continue / 88 , 89 )" errors?
Those numbers look like they are word numbers. Try looking them up on the vocab screen in Companion. That'll tell you which spec is at fault (hopefully).

So I just made sure its not my main.sc causing the issue, as in a new room I get the same bad said spec with the wallet item and also other non declared said syntaxes linked to "look". I've commented out all said syntaxes from the handleEvent in the main.sc except this:

Code: [Select]
(method (handleEvent pEvent &tmp i)
; ////////////////////////////////////////////////////////////////////
; ** This is debug functionality                                   //
; ** Comment it out if you don't want people to cheat in your game //
; ////////////////////////////////////////////////////////////////////
(if (== evKEYBOARD (pEvent type?))
; Check for ALT keys
(switch (pEvent message?)
($2f00 (Show 1)) ; alt-v ; Show visual
($2e00 (Show 4)) ; alt-c ; Show control
($1900 (Show 2)) ; alt-p ; Show priority
($3200      ; alt-m
; Show memory usage
(ShowFree)
(FormatPrint
{Free Heap: %u Bytes\nLargest ptr: %u Bytes\nFreeHunk: %u KBytes\nLargest hunk: %u Bytes}
(MemoryInfo miFREEHEAP)
(MemoryInfo miLARGESTPTR)
(>> (MemoryInfo miFREEHUNK) 6)
(MemoryInfo miLARGESTHUNK)
)
)
($1400      ; alt-t
; teleport to room
(gRoom newRoom: (GetNumber {Which Room Number?}))
)
($1700      ; alt-i
; get inventory
(gEgo get: (GetNumber {Which inventory#?}))
)
($1f00      ; alt-s
; Show cast
(gCast eachElementDo: #showSelf)
)
)
)
; //////////////////////////////////////////////////
; End of debug functionality                     //
; //////////////////////////////////////////////////
(super handleEvent: pEvent)
(if (or (!= (pEvent type:) evSAID) (pEvent claimed:))
(return)
)
(FormatPrint "Received SAID event in main.sc")
(cond
((Said 'look>')
(cond
((Said '/carpet,down')
(Print 0 115) ; It just lies there, under your feet.
)
((Said '/air,ceiling')
(Print 0 116) ; It's still up there!
)
((= i (gInv saidMe:))
(if (i ownedBy: gEgo)
(i showSelf:)
else
(Print 0 112) ; You see nothing special.
)
)
(else
(switch (Random 42 44)
(42
(Print 0 113) ; It's just as it appears.
)
(43
(Print 0 114) ; It doesn't look interesting.
)
(44
(Print 0 112) ; You see nothing special.
)
)
(pEvent claimed: 1)
)
)
)
)

I've checked the Vocab.000 and see in the "group" column number 88 and 89 refer to words described as nouns I've added. Removing them don't seem to do anything.

What is the process that the (method (handleEvent pEvent) uses. Checks local room first, then checks main.sc then...... ?
its only happening with "look". I have the above look syntax defined in my main.sc and in the new room I'm testing I have a condition:
Code: [Select]
((Said 'look>')
            (cond
                ((Said '/machine,slot')
                    (Print  {Natives Inc Casino machines.})
                )
                ((Said '[/!*]') ; just "look"
                    (Print {test})
                    )
If I type "look chair" I get the bad said spec also but it resolves the look statement using main.sc (Print 0 113) ; It's just as it appears. Could something be corrupt?

Title: Re: Money, cash greenback
Post by: Doan Sephim on August 20, 2025, 11:32:21 AM
The script will produce first what is in the roomscript, but if it is not parsed there, it will check the main script.
I put all the code you posted into my game and tested it without any error. Could you perhaps post more of your code? Sometimes it's just a missing '/' before a noun that can cause problems down the line.
If you could give me your whole main script's handleEvent method, I could take a look.
Title: Re: Money, cash greenback
Post by: lskovlun on August 20, 2025, 11:38:52 AM
SCI Companion shows the group number in hex for some reason. In that case, you need to find group numbers 58 (hex) and 59 (hex) instead.
Title: Re: Money, cash greenback
Post by: robbo007 on August 20, 2025, 12:41:03 PM
SCI Companion shows the group number in hex for some reason. In that case, you need to find group numbers 58 (hex) and 59 (hex) instead.

OMG!!!  You can go over code 100 times and not see something thats in plain daylight.

Hex code 58,59 in the Vocab file pointed me to the area and I saw this. The closing parenthesis on my inventory item should not be there. Removing it resolved the Bad said spec.

Code: [Select]
(instance CROWEBAR of Iitem
(properties
said '/crowebar, crowbar)'
description 101 ;The Crowebar \05_ This thing looks tough.
owner 0
view 227
loop 0
cel 0
script 0
name "Crowebar \05_"
)
)

Thanks for all your suggestions everybody and sorry for the long post...
Title: Re: Money, cash greenback
Post by: Kawa on August 20, 2025, 12:50:41 PM
OMG!!!  You can go over code 100 times and not see something thats in plain daylight.
C++ game project, tried to load a 3D model with more than 50 bones in a structure that only has space for that many bones. Drove me damn near insane for a week before someone found out on my behalf that that was the issue.
Title: Re: Money, cash greenback
Post by: lskovlun on August 20, 2025, 01:11:05 PM
Kawa, maybe we need to make this print group numbers in decimal? The use cases for hex notation here are rather narrow (mainly related to the special tokens which are located at the top of the 12-bit range). And the interpreter uses decimal.
Title: Re: Money, cash greenback
Post by: lskovlun on August 20, 2025, 01:22:35 PM
BTW, if you don't intend to distinguish crowebar and crowbar anywhere, you can just give them a single group number. That's kind of the point of them.
Title: Re: Money, cash greenback
Post by: Kawa on August 20, 2025, 01:47:23 PM
Kawa, maybe we need to make this print group numbers in decimal? The use cases for hex notation here are rather narrow (mainly related to the special tokens which are located at the top of the 12-bit range). And the interpreter uses decimal.
Ten-four, supreme space cadet sir!

*loads up MSVC*

Update: the next Nightly Build should have this change in it.
Title: Re: Money, cash greenback
Post by: robbo007 on August 20, 2025, 02:36:00 PM
Kawa, maybe we need to make this print group numbers in decimal? The use cases for hex notation here are rather narrow (mainly related to the special tokens which are located at the top of the 12-bit range). And the interpreter uses decimal.
Ten-four, supreme space cadet sir!

*loads up MSVC*

Update: the next Nightly Build should have this change in it.

Any chance your fork of SC can support Windows XP :)
Title: Re: Money, cash greenback
Post by: Kawa on August 20, 2025, 02:58:14 PM
Any chance your fork of SC can support Windows XP :)
I guess there is a setting to make it target XP... and I mean in Visual Studio, not this.

Edit: https://helmet.kafuka.org/sci/SCICompanion_XP.exe freshly made for you. I don't know if it'll work, but lemme know. (Also includes the decimal word groups)
Title: Re: Money, cash greenback
Post by: robbo007 on August 20, 2025, 03:42:59 PM
Any chance your fork of SC can support Windows XP :)
I guess there is a setting to make it target XP... and I mean in Visual Studio, not this.

Edit: https://helmet.kafuka.org/sci/SCICompanion_XP.exe freshly made for you. I don't know if it'll work, but lemme know. (Also includes the decimal word groups)

Amazing thanks. it seems to load and run things fine :)
Wow...I see it detects inconsistencies in the code that he original version doesn't. I'm going to have to check the readme on your github to see what has changed.


Title: Re: Money, cash greenback
Post by: Doan Sephim on August 21, 2025, 10:24:06 AM
Before I forget to mention, there's a parser command in your main script that I suspect doesn't work as you intend.
Code: [Select]
(cond
((Said 'look>')
(cond
((Said '/carpet,down')
"Look carpet" will work, although I'm not sure why this would be in your main script...unless there's a carpet in every room in the game.
But "look down" doesn't parse as "down" I believe is an adverb. I think the game will just give the standard "look" command if the player types "look down."

Just a small observation.
Title: Re: Money, cash greenback
Post by: robbo007 on August 21, 2025, 10:32:11 AM
Before I forget to mention, there's a parser command in your main script that I suspect doesn't work as you intend.
Code: [Select]
(cond
((Said 'look>')
(cond
((Said '/carpet,down')
"Look carpet" will work, although I'm not sure why this would be in your main script...unless there's a carpet in every room in the game.
But "look down" doesn't parse as "down" I believe is an adverb. I think the game will just give the standard "look" command if the player types "look down."

Just a small observation.

ahh ok thanks for spotting that :) I'll review it.. It's a luxury to have a second set of eyes on your code :)