Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/08/26 22:41
Stooq now requires an API key
by VHX. 06/08/26 20:14
ZorroGPT
by TipmyPip. 06/06/26 12:36
Zorro 3.01 recoded MMI function issue
by TipmyPip. 06/04/26 05:44
SGT_FW
by Aku_Aku. 05/31/26 11:05
Issues resuming trades on Demo account
by Martin_HH. 05/22/26 13:31
XTB
by pr0logic. 05/18/26 12:27
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (TipmyPip), 3,688 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Seraphinang, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Changing Function/Action at runtime? [Re: DJBMASTER] #276068
07/03/09 10:34
07/03/09 10:34
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
Code:
def get_actions(filename): # get entity actions from wmb file
    actions = []
    f = open(filename, "rb")
    f.seek(4+8+8+8+8+8+8+8+8+8+8+8+8+8+8+8)
    offset, length = struct.unpack("ll", f.read(8))
    f.seek(offset) # jump to object list
    object_offsets = []
    for i in range(struct.unpack("l", f.read(4))[0]):
        object_offsets.append(struct.unpack("l", f.read(4))[0])
    for o in object_offsets:
        f.seek(offset + o)
        type = struct.unpack("l", f.read(4))[0]
        if type == 7 or type == 3: # entity
            f.seek(offset + o + 4 + 4*3*3)
            # strings don't always seem to start at the same position!? -> regular expression necessary
            n = re.split("\x00+", struct.unpack("86s", f.read(86))[0])
            if n[2]: # action exists
                actions.append((n[0], n[2])) # entity name, action name
    f.close()
    return actions



and here is my level_load() function:
Code:
def level_load(filename, g):
    # only keep threads where my isn't set
    new = [thread for thread in threads if thread[2] is None]
    del threads[:] # delete all elements but keep the original list instance
    threads.extend(new)
    # load level
    _level_load(filename)
    # start actions
    if filename[-3:].lower() == "wmb":
        if not os.path.exists(filename):
            for path in e.pPaths: # look for file in all paths that got added with add_folder()
                f = os.path.join(path, filename)
                if os.path.exists(f):
                    filename = f
                    break
        actions = get_actions(filename) # get entity actions from wmb file
        for action in actions:
            entity = ent_for_name(action[0])
            entity.eflags &= ~ANIMATE
            entity.emask |= DYNAMIC
            e.my = entity
            eval(action[1] + "()", g)
            e.my = None



Re: Changing Function/Action at runtime? [Re: ventilator] #276069
07/03/09 10:39
07/03/09 10:39
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline OP
Serious User
DJBMASTER  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Thanks, i'm using c#, i'll try and see if i can convert it...

I can't find anything in the manual about the structure of the .wmb file format. I've found some info in the Wiki, but it doesn't specify anything about actions so i've no clue how to change the actions.

Re: Changing Function/Action at runtime? [Re: DJBMASTER] #276076
07/03/09 10:50
07/03/09 10:50
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline
Serious User
pegamode  Offline
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Just take a look at the WMB-Format-Definition:

http://www.conitec.net/beta/prog_mdlhmp.html

Read WMB_ENTITY and get "action".

Re: Changing Function/Action at runtime? [Re: pegamode] #276084
07/03/09 11:24
07/03/09 11:24
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline OP
Serious User
DJBMASTER  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
i'm sorry if i'm being totally dumb, but do i read the WMB_ENTITY/action fields through lite-c, or can i do it through C# using I/O functions?

I'm not entirely sure how i would read them, as i've never used this before.

Re: Changing Function/Action at runtime? [Re: DJBMASTER] #276094
07/03/09 11:39
07/03/09 11:39
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline
Serious User
pegamode  Offline
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
As you could see it in ventilator's script (which isn't lite-c, too) you have to use I/O-functions of your programming language (in your case C#).

Use the offsets (you'll find them in the manual posted above) to get to the right position in the file and read out the action.

Re: Changing Function/Action at runtime? [Re: pegamode] #276099
07/03/09 11:52
07/03/09 11:52
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline OP
Serious User
DJBMASTER  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
i'm not trying to read out the actions, i want to write them in. I'll try and see what i can do...

Last edited by DJBMASTER; 07/03/09 11:53.
Re: Changing Function/Action at runtime? [Re: DJBMASTER] #276104
07/03/09 12:04
07/03/09 12:04
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline
Serious User
pegamode  Offline
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
That'll work the same way ... just use the write command instead of read.

And you have to be careful not to write more bytes than were preserved for the action name.

Re: Changing Function/Action at runtime? [Re: pegamode] #276111
07/03/09 12:21
07/03/09 12:21
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline OP
Serious User
DJBMASTER  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
well the entities will have no action attached when they are compiled into the .wmb, and i will then write an action name given from my utility. I'm sure it can't be more than 20 characters. As long as i don't exceed 20 i should be fine right?

Re: Changing Function/Action at runtime? [Re: DJBMASTER] #276113
07/03/09 12:25
07/03/09 12:25
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline
Serious User
pegamode  Offline
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Yes. I think you just have to be sure that the string is null-terminated.

The action is defined as follows:

char action[20];

So, you can use 20 letters and the last is the null-terminator (in most languages you can use the escape sequece \0 ).


Re: Changing Function/Action at runtime? [Re: pegamode] #276117
07/03/09 12:35
07/03/09 12:35
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline OP
Serious User
DJBMASTER  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Ok, i'm getting somewhere now. I've converted as much as i can to C#, and i can read the name of the entity,filename and action from the .wmb file.

I'm having a little trouble writing names back to the file though.

Last edited by DJBMASTER; 07/04/09 09:07.
Page 2 of 3 1 2 3

Moderated by  old_bill, Tobias 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1