Author Topic: Joke text resoruce LSL3  (Read 12143 times)

0 Members and 3 Guests are viewing this topic.

Offline robbo007

Joke text resoruce LSL3
« on: September 03, 2025, 06:02:23 AM »
Hi guys,
I'm just trying to understand the ComicScript instance in room 340 in LSL3. I understand what the script is doing but not sure why in the text resource 341 (which is where the joke text is located) there are what seems like hex codes after each joke? What do the codes do? Which part of the script uses them?
Thanks,



Offline lskovlun

Re: Joke text resoruce LSL3
« Reply #1 on: September 03, 2025, 07:08:08 AM »
The way it's set up, a joke has a maximum of five messages. Any excess ones are marked by a space character (which is impossible to see in the screenshot). And it's not hex; it seems to be a joke number and an alphabetic character. But that's a red herring; the only thing the code looks at is that space character.

Offline robbo007

Re: Joke text resoruce LSL3
« Reply #2 on: September 03, 2025, 07:23:19 AM »
The way it's set up, a joke has a maximum of five messages. Any excess ones are marked by a space character (which is impossible to see in the screenshot). And it's not hex; it seems to be a joke number and an alphabetic character. But that's a red herring; the only thing the code looks at is that space character.

ok thanks. Could it be to do with the group numbers? Or so that the ComicScript knows when to finish?

Code: [Select]
(11
(aComic setCycle: Walk viewer: 0)
(= count 0)
(repeat
(++ count)
(= i (Random 0 42))
(if testCount
(= i (++ testCount))
(= [toldJoke i] 0)
)
(if (== [toldJoke i] 0)
(= [toldJoke i] 1)
(= group2 (= group1 (Random 49 51)))
(= group3 group1)
(while (== group1 group2)
(= group2 (Random 49 51))
)
(while
(or (== group3 group1) (== group3 group2))
(= group3 (Random 49 51))
)
(for ((= j 0)) (< j 5) ((++ j))
(= k 0)
(Format @jokeString 340 49 341 (+ j (* i 5))) ; "%s"
(if (!= 32 (StrAt @jokeString 1))
(for
((= line 0))
(< line (StrLen @jokeString))
((++ line))

(if (== 47 (StrAt @jokeString line))
(StrAt @jokeString line 37)
(switch (StrAt @jokeString (++ line))
(group1
(= [jokeArgs k] @ethnicGroup1)
(++ k)
)
(group2
(= [jokeArgs k] @ethnicGroup2)
(++ k)
)
(group3
(= [jokeArgs k] @ethnicGroup3)
(++ k)
)
)
(StrAt @jokeString line 115)
(++ line)
)
)
(Printf
@jokeString
[jokeArgs 0]
[jokeArgs 1]
[jokeArgs 2]
[jokeArgs 3]
[jokeArgs 4]
)
)
)
(if (> testCount 42)
(if testCount
(Print 340 50) ; "All done."
(= testCount 0)
else
(Print 340 51) ; "error"
)
)
(aDrummer setCycle: End)
(if (> (DoSound sndCHECK_DRIVER) 5)
(gSoundFX number: (Random 21 27) loop: 1 play:)
)
(break)
)
(if (>= count 1000)
(= state 12)
(break)
)
)
(= seconds 2)
)

https://github.com/sluicebox/sci-scripts/blob/main/lsl3-dos-1.021/src/rm340.sc

There seem to be 42 jokes in total.Then the last part of the 341 text resource has:

Code: [Select]
done2
done1
done3
done4
done5

Regards,
« Last Edit: September 03, 2025, 07:40:16 AM by robbo007 »

Offline Kawa

Re: Joke text resoruce LSL3
« Reply #3 on: September 03, 2025, 08:26:37 AM »
The "done" lines also all start with a space.

Offline lskovlun

Re: Joke text resoruce LSL3
« Reply #4 on: September 03, 2025, 09:38:28 PM »
The original code (which we have) has a LAST_JOKE define which is equal to 42. The toldJoke array is a bit larger, because
Code: [Select]
        [toldJoke       (+ 3 LAST_JOKE)]                        ;**     a little extra never hurts
The code will try 1000 times to tell all the jokes (I don't care to calculate the probability of that happening), and it it can't, it jumps straight to the duck sequence. If we succeed before that, of course it doesn't take 1000 jokes.

Offline doomlazer

Re: Joke text resoruce LSL3
« Reply #5 on: September 04, 2025, 01:24:04 AM »
Checking a thousand times seems wasteful and, as mentioned, has a chance not tell every joke each playthrough. Would Fisher-Yates save or increase resource usage in an SCI implementation here? That's &tmp [jokeList 42], right? Seems smaller than most string literals.

I guess with only 42 jokes you might not burn through all 1k iterations, but you could shuffle once on room load and increment over the list. It would greatly simplify the code; not that the Sierra devs had time for optimization.

You could probably assign the initial values in a loop instead of defining [jokeList 42] = [0 ... 41] in local. ScummVM might throw a console warning though.
« Last Edit: September 04, 2025, 02:38:14 AM by doomlazer »

Offline Kawa

Re: Joke text resoruce LSL3
« Reply #6 on: September 04, 2025, 03:04:38 AM »
See also the copy protection screen in LB2, which does take a finite set of options and shuffles them.

https://helmet.kafuka.org/logopending/2020/08/15/sci-decompilation-and-weird-loops/

Offline robbo007

Re: Joke text resoruce LSL3
« Reply #7 on: September 04, 2025, 10:42:36 AM »
Thanks everyone. Its all clear now. Amazing..


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

Page created in 0.017 seconds with 18 queries.