Author Topic: Dynamic Said() strings  (Read 6284 times)

0 Members and 1 Guest are viewing this topic.

Offline gumby

Dynamic Said() strings
« on: July 23, 2010, 11:02:40 PM »
I want to do this because I've dynamically added props to all my rooms and I need some way handle interactions with all the props currently in the room.  I have an array of all current room props, so I figured I'd just iterate through the array and apply a generic 'take' said string (for example) for each one.  Putting that aside, stripped down, here's a basic example of what I'm trying to do:

Code: [Select]
(var aString, bString)     // I also tried (var aString[50], bString[50]) variations...

StrCpy(aString "take/")
Print(aString)             // This displays 'take/'
StrCpy(bString "lantern")  // Obviously, this would be a variable of some sort, for testing I hard-coded it
Print(bString)             // This displays 'lantern'
StrCat(aString bString)    // Hopefully the result would be take/lantern, right?  Game locks up here...
       
(if(Said(aString))
   // Do stuff here based on what was specified for bString
)

The StrCat command is going awry - I'm doing something wrong, I've attempted to debug it with Print() statements and my efforts result in corrupted text, sometimes empty strings, sometimes game just freezes up completely).  Has anyone successfully used these string kernel functions?  Or does anyone know a better way to do what I'm attempting? 





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

Offline gumby

Re: Dynamic Said() strings
« Reply #1 on: July 24, 2010, 08:49:25 PM »
I've put a few more hours into this one and it sure looks like a memory referencing issue.  It's as if I'm referencing non-addressable memory or clobbering memory currently in use.  Throughout my testing I continue to get seemingly 'random' messages (reproducible errors provided the code as whole does not change, but as I remove unrelated code in the script it errors in different ways) - I'll get the SCI real-time engine to throw errors, I'll even get the game attempting to reference undefined text.xxx files (this was bizzare).  Once, I got an error message that was caught by the OS "The NTVDM has encountered an illegal instruction - (occurring within the sciv.exe according to the windows event log).  I have also checked the available heap space within the game, and it appears to be fine.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: Dynamic Said() strings
« Reply #2 on: July 25, 2010, 12:06:11 PM »
I haven't had time yet to give this a go, but I will when I can. My first thoughts though would be to try and back up one step. Instead of trying to make aNewVarible="take/aVariable". How do things work out simply using aVarible in an if said statement.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline gumby

Re: Dynamic Said() strings
« Reply #3 on: July 25, 2010, 02:05:00 PM »
I've looked into this as well.  Here was my results: (assuming in both cases that user entered 'take lantern')

Code: [Select]
(var aVariable)

= aVariable 'take/lantern' 
(if Said(aVariable))     // This evaluates to true
   // code...
)

= aVariable "take/lantern"
(if Said(aVariable))    // This cannot be evaluated, game errors
   // code...
)

From this we can assume that the Said() function does NOT want a string variable type as we know it (double-quoted sets of characters), rather a variable that is not a string (single quoted set of characters) - it's a string but handled differently?

My most recent attempt at this involved putting all the 'take/xxxxx' strings into a text resource and then just pulling them out by index and evaluating them.  However, I ran into the single/double quote problem.

I'm now trying to determine just how to cast a string (double quote) to a singly-quoted string. 
 
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline gumby

Re: Dynamic Said() strings
« Reply #4 on: July 29, 2010, 10:38:34 PM »
I'm beginning to think that this is not possible.  After evaluating all my requirements, I think I've come up with (hopefully) better solution:

My project requirements are basically forcing me to make all game logic available in every room.  This is due to the fact I'm porting from a game language that is verb-centric  (you are free to attempt to do anything in any room with any object and potentially get a different response from the game) instead of room-centric.  I've come up with something that *might* work - I was thinking about making a script for every valid verb available in my game.  Each verb script would handle all possible outcomes with that verb and all the nouns in the game.  Then I would load the script when the verb was encountered.  So the code in each room would be something like this:
Code: [Select]
(if(Said('take>'))
  Load(rsSCRIPT 100)    // This would correspond to my 'take' script
  // run code in my newly loaded script
  Unload(rsSCRIPT 100)  // When safe to do so, unload the script to free up memory
)

(if(Said('drop>'))
  Load(rsSCRIPT 101)
  // run code in my newly loaded script
  Unload(rsSCRIPT 101)
)

// etc... one code block for each verb in game

Ugly, I know, but I can't devise any other way to accomplish this (if this will even work!).  I will report back with my findings...
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: Dynamic Said() strings
« Reply #5 on: July 30, 2010, 09:49:59 PM »
I think I like the idea of a 1 script said/response  In  a way I have done something similar with BC's point & click script. Might I suggest using a currentRoom switch to determine an appropriate response.  I don't know about all this load unload business. I agree with unloading the script at room change, but once is loaded go ahead and leave it loaded. I would probably load it in the init part as a region.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline gumby

Re: Dynamic Said() strings
« Reply #6 on: August 01, 2010, 10:05:34 PM »
I think I've got it figured out.  In the handleEvent method of the room script, put this:

Code: [Select]
(var loadScript)

(if(Said('take'))
  = loadScript ScriptID(200)
  (send pEvent:claimed(FALSE))
  (send gGame:setScript(loadScript))
)

Then, in the script.200 script, put your logic (in this case for the 'take' verb):

Code: [Select]
(instance public TakeVerb of Script
(properties)
(method (handleEvent pEvent)
            (super:handleEvent(pEvent))

    (if(Said('take/lantern'))

  (if(send gEgo:has(INV_lantern))
    Print("You already have it!")
  )(else
       (send gEgo:get(INV_lantern))
  = tempProp roomProps[INV_lantern]
                       (send tempProp:hide())
  )   
     
    )
)
)

Note that the script.200 has some code that doesn't quite relate to the current discussion:  I've put all my props in a global array (roomProps) that is populated upon init() of the room script (more on this after I complete my generic 'take/drop' functionality - which allows you to take/drop items in any room & be able to 'retake' them).

Basically, the room script handles the 'take' input string, parses it and fires the send event, which we trap then 're-send' to the script.200 (TakeVerb) script (by setting the event claimed to 'false').

The only thing I couldn't get working was the 'unload' portion - I tried several different function calls, but after examining the memory, the usage didn't seem to change (at least significantly).  I'll probably revisit this and attempt to solve it when my verb scripts get very large.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline troflip

Re: Dynamic Said() strings
« Reply #7 on: June 10, 2016, 11:09:18 PM »
Just came across this old thread, and I figured I'd post for any future readers.

There are two problems with what Gumby was originally trying to do:

1) said strings are not strings. They are tokenized at compile time (by looking up the word groups each word belongs to - hence the compile errors if you use an unknown word), and so they are just a sequence of numeric tokens. You can't convert from string to said tokens at runtime, since there's no way to access the vocab from script.

That said, you could probably manipulate memory and piece together the token sequences at runtime.

The problem is, they don't terminate in the null character like strings do. Instead, they terminate in $ff (or255).

You could use StrAt to find this token, and keep appending tokens to a buffer until you encounter an $ff. Then of course, terminate the final result with a $ff also.

2) When using StrCat (which wouldn't be useful for piecing together said sequences, because it just keeps going though memory until it finds a null character), you need to make sure the destination string is in a buffer that has enough room to append the source string onto it. Otherwise you'll be writing over other things in memory and causing all sorts of corruptions.
Check out my website: http://icefallgames.com
Groundhog Day Competition


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

Page created in 0.058 seconds with 23 queries.