Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Tracking which lines have been said...  (Read 2933 times)

0 Members and 1 Guest are viewing this topic.

greg

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
Tracking which lines have been said...
« on: October 29, 2006, 03:35:15 PM »

I'm trying to track what dialogue lines a character has said (and how many times he has said them).

To do this, my first thought was to use a hash table, a la:

Code: [Select]
// stringId is the ID of the dialogue line in the string table (in the format X_##_##_##, which is [ActorID]_[RoomID]_[ObjectID]_[LineId])
if (actor.dialogue[stringID]) {
   actor.dialogue[stringID] = actor.dialogue[stringID] + 1;
} else {
   actor.dialogue[stringID] = 1;
}

Since WME doesn't have hash tables but instead approximates them with the variable.subvariable format, my next thought was to do something like:

Code: [Select]
var lineState = actor.dialogue;
if (lineState.stringId) {
   lineState.stringId = lineState.stringId + 1;
} else {
   lineState.stringId = 1;
}

This wouldn't work though, because lineState.stringId would be treated as "lineState.stringId" rather than being resolved to lineState.X_##_##_##.

I suppose I could create a hash function which turns the stringId (X_##_##_##) into an integer (######) and then use that integer to index into an array of length maximumPossibleNumberOfLinesGivenStringIdFormat (######, which would be, egad, 1,000,000).

Is there a better--or more memory efficient--way of tracking which lines have been said, though?

Thanks for your help!

Greg
Logged

greg

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 18
    • View Profile
Re: Tracking which lines have been said...
« Reply #1 on: October 29, 2006, 05:36:56 PM »

Main question:

For global variable x and w = x.y.z (or w = x.y[z]), how can I edit w so that future references to x.y.z (or x.y[z]) (from different scripts, etc) will reflect the updated w?

Explanation:

As a corrolary to the previous post, I'm now trying this method:

Code: [Select]
// if actor.dialogue[stringId] is true, then the actor has said the line corresponding to stringId.
// in the following code, "this" refers to the actor who's speaking

var string_state = this.dialogue; // because wme doesn't like this.dialogue[stringId]
method TalkOnce(stringId) {
var string_state = this.dialogue;
if (!string_state[stringId]) {
string_state[stringId] = true;
this.Talk(stringId);
}
}

However, even though I'm setting actor.dialogue[stringId] to true, the next time I call the method, actor.dialogue[stringId] has reverted to its previous null value.  I suspect this is a pass-by-reference/pass-by-value problem.  Namely, when I update string_state, I'm updating a copy of actor.dialogue (pass by value) rather than the actual actor.dialogue (pass by reference).  Is this true?  If so...

For global variable x and w = x.y.z (or w = x.y[z]), how can I edit w so that future references to x.y.z (or x.y[z]) (from different scripts, etc) will reflect the updated w?

Thanks,
Greg
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Tracking which lines have been said...
« Reply #2 on: October 29, 2006, 07:31:53 PM »

You'll need to assign the value back after modifying it.

Code: [Select]
var string_state = this.dialogue;
string_state[stringId] = true;
this.dialogue = string_state;
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.048 seconds with 23 queries.