Author Topic: Money, cash greenback  (Read 94932 times)

0 Members and 5 Guests are viewing this topic.

Offline robbo007

Money, cash greenback
« 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,




Offline Kawa

Re: Money, cash greenback
« Reply #1 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.

Offline robbo007

Re: Money, cash greenback
« Reply #2 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?

Offline Kawa

Re: Money, cash greenback
« Reply #3 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.

Offline robbo007

Re: Money, cash greenback
« Reply #4 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)
)
)

Offline Kawa

Re: Money, cash greenback
« Reply #5 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.

Offline lskovlun

Re: Money, cash greenback
« Reply #6 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."
                                                )
                                        )

« Last Edit: August 14, 2025, 08:05:11 PM by lskovlun »

Offline Doan Sephim

Re: Money, cash greenback
« Reply #7 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.

Offline robbo007

Re: Money, cash greenback
« Reply #8 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,
 
« Last Edit: August 15, 2025, 07:12:58 AM by robbo007 »

Offline robbo007

Re: Money, cash greenback
« Reply #9 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,

Offline Doan Sephim

Re: Money, cash greenback
« Reply #10 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.

Offline lskovlun

Re: Money, cash greenback
« Reply #11 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).

Offline robbo007

Re: Money, cash greenback
« Reply #12 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?


Offline Doan Sephim

Re: Money, cash greenback
« Reply #13 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.

Offline lskovlun

Re: Money, cash greenback
« Reply #14 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.


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.035 seconds with 22 queries.