• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Tool: Subscript: The next step for scripting

5,256
Posts
16
Years
  • Oh, actually, I have a request for when you get regular scripting working. Do you think it'd be possible to add support for multiple scripting engines? That way, one could use this for both battle scripting and regular scripting. That would be a great asset for the community, particularly with how many people are unable to use BSP.
     

    Touched

    Resident ASMAGICIAN
    625
    Posts
    9
    Years
    • Age 122
    • Seen Feb 1, 2018
    Ah, adding those variables definitely makes things better.
    Will you also allow us to create functions?

    Yeah, but I haven't quite worked out the mechanics. I'm thinking of using the import tools to perform multiple functions:

    • Import ASM routines
    • Python Modules
    • Binary Data
    • Definition lists

    So then you'll be able to say

    Code:
    import routine
    thumb(routine)

    And it'll automatically insert the routine (and align) and a callasm offset + 1. Also, if you import a Python module, you'll be able to add functions - I've added an example of how this works (with decorators) in another post.

    But I also plan to use the regular Python syntax for functions:

    Code:
    def function(args):
        pass

    But I'm really not sure how that will be translated. Maybe a call command and end with a return? Set lastresult? I've yet to work something out. If someone wants to suggest something they'd be more than welcome.

    He said it will be Open Sourced, so make what youwhat you will from that
    Also, what will the program's name be?
    TNSSE? (The next step Script Editor)
    Maybe just TNS.
    Any ideas? (not that it matters too much as of right now)

    I really haven't thought of a name for this to be honest. I've named the Python module I wrote "subscript", but I'm not sure that that's a good name. I'm not really a fan of all the acronyms, so I might pick something that's one word - to make it stand out more? But suggestions are welcome. I'm coding a test GUI now, so I'll probably need a name soon.

    Oh, actually, I have a request for when you get regular scripting working. Do you think it'd be possible to add support for multiple scripting engines? That way, one could use this for both battle scripting and regular scripting. That would be a great asset for the community, particularly with how many people are unable to use BSP.

    Yeah, I was thinking about doing that. I've made it modular as best I can, but some things will definitely need to be rewritten for different scripting engines (the types and control flow logic, for example). But I'll add it to the planned features list.
     
    3,830
    Posts
    14
    Years
    • Age 27
    • OH
    • Seen May 10, 2024
    A way you could set up the coding to work with the custom functions is to just have everything in a function of some kind, and require a main() function for the start of the script.

    Sort of like this...
    Code:
    # This would be a requirement
    def main():
         ...
         do_something()
         if ... = False:
              do_something_2()
         ...
         end
    
    # And then the user can define as many of these as they want.
    def do_something():
         ...
         # It could be a return, which would tell you to make references to it a call
         return
    
    def do_something_2():
         ...
         # Or it could be a end, which would tell you to use a goto
         end

    How does that look?
     

    Touched

    Resident ASMAGICIAN
    625
    Posts
    9
    Years
    • Age 122
    • Seen Feb 1, 2018
    Ok, I downloaded this and python 3.4, how do I make it function?

    If you wish to check out the demo, you can use the command line interface as per the example in the first post. Type "python3 cli.py --help" to see a list of available flags. It won't help much if you want to make a script with it though - I haven't implemented many functions.

    A way you could set up the coding to work with the custom functions is to just have everything in a function of some kind, and require a main() function for the start of the script.

    Sort of like this...
    Code:
    # This would be a requirement
    def main():
         ...
         do_something()
         if ... = False:
              do_something_2()
         ...
         end
    
    # And then the user can define as many of these as they want.
    def do_something():
         ...
         # It could be a return, which would tell you to make references to it a call
         return
    
    def do_something_2():
         ...
         # Or it could be a end, which would tell you to use a goto
         end

    How does that look?

    Yeah, that's a good idea. Maybe I could also make it set lastresult if you try to return a value? I'm not so sure about the main method though - what happens to the code outside of it? But I'll definitely use the other two, thanks :)
    Maybe I'll also do inline functions? If you only call a particular function once, a call is useless? Or is that not such a great idea (maybe you want to have separate entry points for your script)?
     

    sky_queen3

    Mimikyu is cute :3
    271
    Posts
    15
    Years
  • I click it and I get this error: (had to screenshot it 100 times, it flashes pretty much.)

    useage: cli.py [-h] [--raw file] [--rom file] [--offset offset] script
    cli.py: error: the following arguments are required: script

    I'm using 3.4 in Windows 7 if that makes a difference.
     

    Touched

    Resident ASMAGICIAN
    625
    Posts
    9
    Years
    • Age 122
    • Seen Feb 1, 2018
    I click it and I get this error: (had to screenshot it 100 times, it flashes pretty much.)

    useage: cli.py [-h] [--raw file] [--rom file] [--offset offset] script
    cli.py: error: the following arguments are required: script

    I'm using 3.4 in Windows 7 if that makes a difference.

    You can't click it. You have to run it from the command line. I don't want to sound rude, but if you're not sure how to do that (or don't know what that is), then I don't think the demo is going to be of much use to you. Rather wait until I write a GUI for the tool (and complete it) before attempting to use it.
    However, if you really want to check out the demo, then I recommend that you look for a basic tutorial on how to use the Windows command line (Google, or look around here - I'm sure I've seen a tutorial with some command line aspects to it.)
     

    Touched

    Resident ASMAGICIAN
    625
    Posts
    9
    Years
    • Age 122
    • Seen Feb 1, 2018
    Update:

    So, I started work on the GUI (I like to switch projects to keep from getting too bored). Using GTK+ and its Python bindings, I created something resembling an IDE. I've attached some screenshots of the hex editor (which will take a while, I couldn't find one already made, I'm having to draw the whole thing manually) and the built in debugger (using my VBA-M mods with Python bindings) and the script editor (using GtkSourceView for syntax highlighting and code completion).

    If anyone is willing to help out with a Windows or Mac port (I need code to be compiled and PyGObject to be packaged, among other things), then please let me know - this is quite a big project and I'll need all the help I can get.
     

    Touched

    Resident ASMAGICIAN
    625
    Posts
    9
    Years
    • Age 122
    • Seen Feb 1, 2018
    That is one nice looking GUI. :D

    Why, thank you. I find that if a tool embeds an emulator, it's automatically better {:3}

    Some more news :)

    I've built a script debugger, which reads the script struct and shows some useful information about the current script:

    Subscript: The next step for scripting


    Additionally, I've completed the custom functions, as itari suggested. I'm now working on finishing the commands list and the import mechanics. Once I've done this, I'll go back to the GUI, and hopefully by then I'll be ready to release :D

    I've also added another feature:

    The problem: Many hacks overwrite Pokemon. Let's take a hypothetical situation: We've replaced Exeggcute with Piplup. Now, if we want to give the player a Piplup (Level 5, no item) via a script, we either have to say:
    Code:
    givepokemon PKMN_EXEGGCUTE 0x5 0x0 0x0 0x0 0x0
    or
    Code:
    givepokemon 0x66 0x5 0x0 0x0 0x0 0x0

    Both of these are annoying. We either have to remember which Pokemon we replaced, or we have to remember its Pokemon number. Urgh

    Solution:

    The solution I came up with is to read the Pokemon names table (0x245EE0 in FireRed) of the currently loaded ROM. This is such a stupidly easy solution that I'm surprised no one did it before now. Now all you have to say is:

    Code:
    givepokemon(Pokemon('piplup'))

    The other arguments default to level 5, and no item. I've also done this with items and moves. But, if you wanted to add an Oran berry to our Piplup, all you'd have to say is

    Code:
    givepokemon(Pokemon('piplup'), item=Item('Oran berry'))

    So basically all you have to remember is the name of the thing you wish to give. The name is case insensitive, so you could just as well say Item('ORAN BERRY'). Of course, the default functionality is preserved. So if remembering arbitrary numbers is your thing, then you can say Item(0x8B) and achieve the same result.
     
    5,256
    Posts
    16
    Years
  • That is a highly intuitive method, I like it! Make sure to make the names table adjustable in an INI file though, because since we've learned how to expand the 'dex, that kind of stuff tends to get repointed.
     

    Touched

    Resident ASMAGICIAN
    625
    Posts
    9
    Years
    • Age 122
    • Seen Feb 1, 2018
    That is a highly intuitive method, I like it! Make sure to make the names table adjustable in an INI file though, because since we've learned how to expand the 'dex, that kind of stuff tends to get repointed.

    Of course. Except it'll probably be json or something. INI files are ugly :(
    I was actually considering trying to implement a repoint detector. But that's difficult if all the loading routines have been repointed, too. I might just give up and make it editable in a config file.
     

    Danny0317

    Fluorite's back, brah
    1,067
    Posts
    10
    Years
    • Age 24
    • Seen Nov 19, 2023
    I have a suggestion if I may. Now, some people may not have any use for it, but I guess it can be helpful to some people like me. Like maybe you can have a tab that shows how a script would look like in Hex. Like for example, if my script is:

    checkattack 0x39

    maybe in another tab it would show 7F 39.

    Not sure if I am explaining myself correctly.
     

    Touched

    Resident ASMAGICIAN
    625
    Posts
    9
    Years
    • Age 122
    • Seen Feb 1, 2018
    I have a suggestion if I may. Now, some people may not have any use for it, but I guess it can be helpful to some people like me. Like maybe you can have a tab that shows how a script would look like in Hex. Like for example, if my script is:

    checkattack 0x39

    maybe in another tab it would show 7F 39.

    Not sure if I am explaining myself correctly.

    Yeah, I'm planning to create a Hex Viewer/Editor (like XSE). I've just got to finish up the Hex Editor widget, which might take a while. But I can dump the compiled hex code as text. The function that does the compiling is fast enough to be called whenever a change is made, so theoretically I could implement a "live" compiler (which is what you seem to be suggesting).
    But I'm curious as to why you would need this. Surely implementing a custom function would be simpler?
     

    Danny0317

    Fluorite's back, brah
    1,067
    Posts
    10
    Years
    • Age 24
    • Seen Nov 19, 2023
    Yeah, I'm planning to create a Hex Viewer/Editor (like XSE). I've just got to finish up the Hex Editor widget, which might take a while. But I can dump the compiled hex code as text. The function that does the compiling is fast enough to be called whenever a change is made, so theoretically I could implement a "live" compiler (which is what you seem to be suggesting).
    But I'm curious as to why you would need this. Surely implementing a custom function would be simpler?

    Wait XSE had one? :O
    Well a few days ago I was trying to find the surf script, and I did, but for that I had to try some things, like checkattack 0x39, but doing that I had to make a script that said that, open it in a hex editor, and copy those bytes. I just thought it could be useful for some things like that. And I wish I could answer your custom function thing, but I don't really know what that means. (._.)
     

    Touched

    Resident ASMAGICIAN
    625
    Posts
    9
    Years
    • Age 122
    • Seen Feb 1, 2018
    Wait XSE had one? :O
    Well a few days ago I was trying to find the surf script, and I did, but for that I had to try some things, like checkattack 0x39, but doing that I had to make a script that said that, open it in a hex editor, and copy those bytes. I just thought it could be useful for some things like that. And I wish I could answer your custom function thing, but I don't really know what that means. (._.)

    Never mind, I didn't realise that that was what you wanted to do (adding commands is one of the features of this tool). I thought you wanted to use raw commands or something. You certainly will be able to do what you ask - you can compile directly to a raw file. XSE has a hex viewer somewhere in its Tools menu. I don't think it's very advanced, but it can decode the Pokemon encoding as well as ASCII.
     

    Touched

    Resident ASMAGICIAN
    625
    Posts
    9
    Years
    • Age 122
    • Seen Feb 1, 2018
    Bump. Updated the main post with links to the GitHub repo.
     
    204
    Posts
    9
    Years
    • Seen Jul 26, 2021
    If i start with scripting, should i start with xse because of the tutorials it already has and then switch to this or is this so easy i can directly start with it?
     

    Danny0317

    Fluorite's back, brah
    1,067
    Posts
    10
    Years
    • Age 24
    • Seen Nov 19, 2023
    If i start with scripting, should i start with xse because of the tutorials it already has and then switch to this or is this so easy i can directly start with it?

    I would say start with XSE, then switch to this once it's ready because then you'll know the syntax for both and that will be better :D
     
    Back
    Top