Module Development > The Forge - Mod Development

Linked lists

(1/2) > >>

svaucher:
This might get a bit technical, but I was wondering the feasibility of creating data structures now, since we have slots and local variables.

This is a bit of a brainstorm:

1/ have a null troop that acts as a placeholder
2/ have a node troop with slot 1 pointing to the next node, or a null troop and slot 2 to the element.

This would simplify iterations significantly because we could simulate closures.
You would invoke a script called "invoke" with two params: the list and a script. The script would be invoked on every element (passing it as the first parameter).

I know there are a few guys here with some coding experience. lisp anyone ;), I'm looking for feedback?

Now for the questions, I haven't modded in a while:

1/ Is there a direct instantiation mechanism (f.e. new troop returned as reg(0)) for troops? or do I need to add them to a party and then retrieve them?
2/ Can slots contain any sort of element?
3/ Has anyone confirmed if recursion functions?
4/ Am I reinventing the wheel?

If this is possible and I implement this, it would arguably become the most boring mod : DATASTRUCTURE MOD !!!

I'm currently trying a bit of code, I'll post what I discover.

Winter:

--- Quote from: svaucher on January 12, 2007, 10:30:20 PM ---This might get a bit technical, but I was wondering the feasibility of creating data structures now, since we have slots and local variables.

This is a bit of a brainstorm:

1/ have a null troop that acts as a placeholder
2/ have a node troop with slot 1 pointing to the next node, or a null troop and slot 2 to the element.

This would simplify iterations significantly because we could simulate closures.
You would invoke a script called "invoke" with two params: the list and a script. The script would be invoked on every element (passing it as the first parameter).

I know there are a few guys here with some coding experience. lisp anyone ;), I'm looking for feedback?

Now for the questions, I haven't modded in a while:

1/ Is there a direct instantiation mechanism (f.e. new troop returned as reg(0)) for troops? or do I need to add them to a party and then retrieve them?
2/ Can slots contain any sort of element?
3/ Has anyone confirmed if recursion functions?
4/ Am I reinventing the wheel?

If this is possible and I implement this, it would arguably become the most boring mod : DATASTRUCTURE MOD !!!

I'm currently trying a bit of code, I'll post what I discover.

--- End quote ---

I don't know what half of the stuff you're talking about means, or how it relates to M&Bscript, but I'll do what I can.

As far as I can figure out about your description and Wikipedia's entry on linked lists, it might be possible in the following way:

Use two troops arrays; temp_array_a and temp_array_b
Fill a troop slot on temp_array_a with the number of the next node (the next troop slot, I suppose)
Fill the same troop slot on temp_array_b with the data associated with the node

Both these slots can then be easily called from anywhere in the module system.


1) The troops in module_troops are a template for the creation of individual agents. Any troop in any party in-game takes after this template. Making any changes to this troop via the module system, to the module_troops tuple or via operations called in-game, will affect all troops of this type.

2) If I understand the word 'element' right in this context:
Slots can contain any reference to anything in the module system. "itm_horse_meat" is just as valid as slot content as the number 6. With regards to the module system, all modular entries are treated as numbers. For example, if you were to perform the following operation:

(troop_add_item,"trp_player",1),

the player would receive a horse meat, since "horse_meat" is the second entry in module_items.py.

3) Recursion has always worked perfectly. I've been using it since 0.731. There are no problems with calling a script from within itself.

4) I think maybe you are, but you could do some interesting things with it.

Cortically,
Winter

svaucher:
Thanks for the answer :)


--- Quote from: Winter on January 12, 2007, 11:00:38 PM ---I don't know what half of the stuff you're talking about means, or how it relates to M&Bscript, but I'll do what I can.

--- End quote ---

I've got an aversion to global variables and I dislike the general organization of data in the modding system. I want to see if I can make it more elegant.
If I can add datastructures, it could simplify modding in general.


--- Quote from: Winter on January 12, 2007, 11:00:38 PM ---]
As far as I can figure out about your description and Wikipedia's entry on linked lists, it might be possible in the following way:

Use two troops arrays; temp_array_a and temp_array_b
Fill a troop slot on temp_array_a with the number of the next node (the next troop slot, I suppose)
Fill the same troop slot on temp_array_b with the data associated with the node

1) The troops in module_troops are a template for the creation of individual agents. Any troop in any party in-game takes after this template. Making any changes to this troop via the module system, to the module_troops tuple or via operations called in-game, will affect all troops of this type.

--- End quote ---

I got an answer here form fisheye:
http://forums.taleworlds.net/index.php/topic,15499.15.html

The problem with troop arrays is that you cannot dynamically create new ones since they're global. It's possible to have some
code to create lists of dynamic size from arrays, so that might be a possibility.

Has anyone written some scripts to use these arrays?

I see that it is possible to spawn parties. Since these parties have unique ids, I assume their slots are not shared, so you could always spawn a party and use its slots.

Anyone know if there's a limit on how many parties we can have?
Also the disabled_flag, does it destroy the party, or could we spawn disabled parties to use their slots?


--- Quote from: Winter on January 12, 2007, 11:00:38 PM ---2) If I understand the word 'element' right in this context:
Slots can contain any reference to anything in the module system. "itm_horse_meat" is just as valid as slot content as the number 6. With regards to the module system, all modular entries are treated as numbers. For example, if you were to perform the following operation:

--- End quote ---

I was hoping so. That means you can add scripts to parties which is very sweet :)

I had been working on adding messengers (1 year ago). Depending on the message you'd send you could store the script of what should be done when the messenger arrives to it's destination or is intercepted. Without slots it was too much of a kludge :(


--- Quote from: Winter on January 12, 2007, 11:00:38 PM ---4) I think maybe you are, but you could do some interesting things with it.

--- End quote ---

I know they could be interesting, but is hacking MBscript to make it work worth it and can it support it since it might be heavy.

Hellequin:
Given that scripts are assigned numerical values like everything else, yes, what you describe should be quite possible.  So, for instance:

[In module_constants.py:]

--- Code: ---slot_script_on_intercept = 30
slot_script_on_arrival = 31
--- End code ---

[In an operations block when the messenger is created:]

--- Code: ---(spawn_around_party, ":Source_town", "pt_messenger"),                                            # Stores the partyID of the spawned party in reg0.
(assign, ":Messenger", reg0),                                   # For clarity and safety - reg0 is not a safe storage spot, it's written to secretly too often.
(troop_set_slot, ":Messenger", slot_script_on_intercept, "script_bite_cyanide_capsule"),
(troop_set_slot, ":Messenger", slot_script_on_arrival, "script_mobilize_the_peasant_militia"),
--- End code ---

[In a different operations block when he arrives at his destination:]

--- Code: ---(troop_get_slot, ":Messenger_script", ":Messenger_that_just_arrived", slot_script_on_arrival),
(call_script, ":Messenger_script", ":This_town"),
--- End code ---

... and so forth.

Yes, I think this should work fine, and it's a good thought - one which hadn't occurred to me.  I don't think it will exactly make anything possible which wasn't before, but it may make certain code much cleaner.  Obviously test first...

- Hellequin

svaucher:
Hellequin - I was doing that in 7.11 without slots, with global variables, then items. Unless something has deteriorated, it should still work.

Navigation

[0] Message Index

[#] Next page

Go to full version