Author Topic: Script Structure  (Read 13087 times)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Script Structure
« on: December 03, 2011, 02:47:42 AM »
So currently the scripts are structured as such, the ID of the script, with leading zeros up to 4 digits.

Code: [Select]
0001-Game_Temp.rb
Now this works fine, and when I load it into the script editor, I drop the beginning ID and the file extension, but I ran into a bit of a snag using this implementation. Aside from not allowing different characters that aren't permitted in file names (which I don't think is a big deal and can care less about), how exactly should we handle changing the script title in the editor? Now obviously I could delete/rename the old file to the name of the new, but I don't like the idea of the constant IO access just to rename a script. Although it would work, it seems a bit messy to be constantly changing the file name and updating the path to match to change a simple string value. Problem is, I can't think of a simple alternative that will still allow us to keep the scripts in  external and separate .rb files...
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline zenvirzan

  • Trained Member
  • *
  • Posts: 19
  • LV: 0
  • The Ruby Addict
    • View Profile
Re: Script Structure
« Reply #1 on: December 03, 2011, 09:48:28 AM »
If worst comes to worst, rather than a name box at the bottom of the script list (if you're doing that):
Make a new dialogue box appear after hitting a rename button (rather than typing in a text box).
That way, when it first opens, it saves the original filename and when closed, if the 2 names are different, it handles it from there :)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: Script Structure
« Reply #2 on: December 03, 2011, 10:14:45 AM »
Yes, I already have contingencies thought up where it won't be doing it with each key stroke and will only do it once when the renaming is complete, but I was hoping for a little cleaner way to do it without the renaming of files and altering paths. It isn't a huge ordeal luckily, I was just hoping for a simple alternative I may have been overlooking.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Script Structure
« Reply #3 on: December 03, 2011, 11:25:00 AM »
They only way how to have them renamed without altering the path is to have an additional file with a file index. I'd like to avoid that additional file. As for renamed, are you able to catch the the textbox losing focus or the ENTER character? I suggest that you put the renaming call there. Until you actually rename the script, the script name should also stay the same in the listbox on the left side. So unlike RMXP, it would not apply every change when a character was added or removed but only when it was really renamed. Keep in mind that closing the editor should also apply the new name (in case somebody changes the name and then hits the OK button while the textbox is still active).
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline SBR*

  • Chaos User
  • ******
  • Posts: 1195
  • LV: -7
  • Gender: Male
    • View Profile
Re: Script Structure
« Reply #4 on: December 04, 2011, 01:03:52 AM »
Perhaps you can put the name in the first line of the .rb file? That way only the content will be changed and the name will stay the same as the ID.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5128
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Script Structure
« Reply #5 on: December 04, 2011, 01:33:13 AM »
!!!
Code: [Select]
#Script-Name: Mainor something similar first line in the file. injected and removed by the script editor on load
then we could just name the files by their script ID
the engine wouldn't have to do anything special only load the scripts though It could use the name for trackback help.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: Script Structure
« Reply #6 on: December 04, 2011, 02:14:27 AM »
I like it. Pretty much the same way you can define encodings etc in the script header, we can simply insert our little tag.  I can just pop the first line on load, and insert again on save. This should work out pretty well.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Script Structure
« Reply #7 on: December 04, 2011, 02:29:47 AM »
And how are you supposed to change the script order then? This would solve the renaming problem only to a degree. If people manually go about editing the .rb file, everything would break down. I'm against the idea, because it's a half-assed solution for a non-existent problem. Either we do it this way or we have an additional file with a file index. Obviously an index will cause many other problems, especially if people add/delete/rename script files manually.
« Last Edit: December 04, 2011, 02:31:23 AM by Blizzard »
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5128
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Script Structure
« Reply #8 on: December 04, 2011, 03:05:56 AM »
they still change the script order with file names. the file name would be the order ID. and if they edited the script themselves that just need to keep the comment line at the top of the file if they wanted the script to have a name the system would not be any easier to break.
and it would allow names to have characters that are not allowed in file-names.

also F0, you should edit the Project frame work to have the saving of script files done there instead of by the editor panel itself if you haven't already.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: Script Structure
« Reply #9 on: December 04, 2011, 03:44:17 AM »
This IS an existing problem, and for the exact same reasons as the alternative you are suggesting, and we are going to have to account for the possibility of a missing file either way we choose to go this, so that makes no difference. A simple insertion/deletion of a script is going to require the renaming of every script under it, which is not cool.

This problem could be solved by deleting the directory's contents and remaking it all with each save, which would solve all these problems, but I am not crazy about the idea, but it would be the least prone to bugs and user sabotage.

@Ryex: I have a static manager class for the script editor, it handles saving. The script objects are stored in Kernel.GlobalObjects under the key "Scripts".
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5128
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Script Structure
« Reply #10 on: December 04, 2011, 04:12:11 AM »
but the scripts should not be saved until the project it self is. so simply have the project system tap into the manager you created to save the scripts when it saves.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Script Structure
« Reply #11 on: December 04, 2011, 10:21:05 AM »
Then we would still have all the problems that F0 described, except that we would have script names that allow any kind of characters. When you insert a new script, the file order would have to be saved as F0 already explained renaming lots of scripts. Why is it so important to be able to use any kind of character in a script name? That's why I called it a non-existent problem, because it's not. If we really, REALLY need users to be able to use any kind of ASCII character in their script name, we can always use escape characters for that. e.g. # could be the escape character. If you need #, it would write #23 and it you need anything else, it would write down another hex code (like #FF). Obviously this could result in long file names if we actually allowed unicode characters as we would need an 8 digit hex in form of #FFFFFFFF.

The alternative, a script index, is very risky. If you delete that script index file, all your script names and script order would be messed up. Remember script corruption in RMXP when the saving was aborted where you would lose a big deal of your scripts? This can't happen if we have file names and no script index. The worst case scenario is that you lose a few scripts in between instead all scripts after, e.g. the 10th script or something like that.

As for the saving, didn't we use tabs? You could edit stuff separately and then save just what is in the tab, am I right? The same should apply to scripts. Yes, obviously inserting a script would require renaming a lot of files. But this small complication is nothing compared to risking losing all script names and the script order when losing a script index.

BTW, have you made sure that UTF8 files are properly loaded and saved?
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: Script Structure
« Reply #12 on: December 04, 2011, 04:44:10 PM »
Yeah, I'm using UTF8, I found out real quick when it threw an error trying to display a script and it said there were illegal characters. The Scintilla library has get and set text methods specifically for UTF8, so it made that easy luckily.

As for the index, I thought we could write the data inside the main project file. We would need an alternative for after encryption and the project file no longer exists, but it should prevent tampering.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5128
  • LV: 197
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: Script Structure
« Reply #13 on: December 04, 2011, 05:47:16 PM »
Ok how about this.

we want the system that the user can edit and change from outside the editor with minimal hassle right? well no matter what we do with file names the system is far to easy to break and a big hassle when you want to add a script or change the order.

and while a index might cause problem it could be done in such a way that it is really easy for the user to edit and easy to repair should something go wrong. here is my proposal.

Code: (scripts.index) [Select]
Game_Temp.rb|Game Temp
Game_System.rb|Game System
Game_Switches.rb|Game Switches
...
...
Scene_Gameover.rb|Scene Gameover
Scene_Debug.rb|Scene Debug
Main.rb|Main

The index works like so.
the load order would be the order in which the scripts are in the file this way inserting a script is as simple as inserting a line where you want it to go
the index maps filenames to script names. one script per line and separated by a '|' character
the loader would read each line up to the first '|' and take that as the file name and then read the rest of the line as the script name
with this method if the index gets corrupted or removed it is easy to repair and files never have to be renamed
« Last Edit: December 04, 2011, 06:43:51 PM by Ryex »
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: Script Structure
« Reply #14 on: December 04, 2011, 06:18:53 PM »
I have no problem with that. I can have an alert when a script is not found in the case that it is misspelled or missing, as well as compare the list to the directory, and offer to import scripts that are not found on the list. That way the user can simply copy-paste .rb files into the folder, and have them be imported easily when the script editor is opened.

@Blizz: Will that pose any problems loading the scripts in the engine, or do you foresee any other problems with that before I implement it?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Script Structure
« Reply #15 on: December 04, 2011, 08:33:36 PM »
we want the system that the user can edit and change from outside the editor with minimal hassle right?

No. We want a system that is least likely to break if he tries to change it from outside the editor.



Alright. After a bit of thoughtful thinking and taking everything into account, this is how we will do it.

1. There will be a file called "index" without extension. This file includes script filenames and script names in the format that Ryex has proposed. This file is GENERATED by the editor each time a script has been saved, added or deleted.
2. File names will be NUMBERS. We can't use actual names, because obviously two scripts can have the same filename and we should spare the user of having to think about filenames.
3. When a new script is being added, all file names have to be checked. Basically start counting from 0 and check whether "%d.rb" exists. As soon as it does not exist, create that file and add in "index" the newest entry. The "index" file should not be used to check which files there are, there should always be an actual file exist test, because people can mess with the files without "index" being updated.
4. Each time "index" is generated and saved, it should check whether all files exist and if everything is alright. If there are problems (e.g. referencing a missing file), the user should be notified and "index" should NOT be saved.

Number 3 and 4 are mostly the reason why I am against index files, but if you want it so badly, have fun coding this mess.

@F0: I saw the script a script editor screenshot the other day. IDK if that's really old or something, but it looked like RMXP. I thought we were going to allow users to open single scripts in tabs. And no, loading this is no problem. I can make the edits work in 5 minutes.

In any case, the biggest problem is with the editor, because you can manually mess with the files. Maybe all script files should be loaded into memory when the editor starts just like in RMXP.
« Last Edit: December 04, 2011, 08:35:11 PM by Blizzard »
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: Script Structure
« Reply #16 on: December 04, 2011, 09:14:16 PM »
You really seem to be against an index file. Its not that we are so "for" it, its just that no one has come up with a better alternative.

Here's another alternative:

  • I have already created a "Script" Python class, which has methods for getting/setting text, tracking cursor position, getting the name, path, etc. It also assigns the ID of the script using the load order with the numbering system
  • We can load all the scripts, and create a list of these "Script" objects when the Script Editor opens
  • If a script is inserted/deleted, it would be simple to do a slice and increment/decrement the ID of all scripts under it
  • On save, regenerate the script name and path something like this:
Code: [Select]
def GetPath( self ):
    prefix = str(self.Id).zfill(4)
    filename = str.join([prefix, self.name, '.rb'])
    path = os.path.join(dir, filename)
  • The only problem here that I foresee is that we would need to remove any .rb file in the directory that was not found in the scripts

I can easily create a tabbed interface for the editor, I need only to turn a few variables to arrays and update the templates file.
« Last Edit: December 04, 2011, 09:15:31 PM by ForeverZer0 »
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Script Structure
« Reply #17 on: December 04, 2011, 09:29:33 PM »
My main reason against a script index is that if that file is lost, your scripts are basically useless or you have to put them back in order. A file naming convention from 0001 and so one would avoid that possibility. If one file is lost, no big deal, just update the order and the user can add that script back in (if it was an external one that can be downloaded from somewhere obviously). That's my main concern. While working on CP over the course of 4 years, my Scripts.rxdata has become corrupted several times. Luckily every time I had an older backup and I hadn't updated the scripts in a while. Only once I lost a few bugs fixes over the course of a few days and had to use a backup without those fixes. Luckily I was able to get it done within a few hours. God, was I pissed that day.

Actually I don't think we'd have to do much if we kept the numbering. Basically every file that doesn't follow the convention of %04d-NAME.rb is ignored. They don't have to be deleted. If a user would add a file that followed the convention, it would obviously be updated on the next startup. e.g. Somebody adds 0011-LOL_SCRIPT.rb and we have already 0011-Game_Actor.rb, we would obviously load first everything before 0011-Game_Actor.rb, then 0011-Game_Actor.rb, then 0011-LOL_SCRIPT.rb, then everything after 0011-LOL_SCRIPT.rb and finally rename all scripts because 0011-LOL_SCRIPT.rb disrupted the order.
« Last Edit: December 04, 2011, 09:35:04 PM by Blizzard »
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: Script Structure
« Reply #18 on: December 04, 2011, 09:57:13 PM »
Come to think of it, lets just keep the original naming convention of "%04d-NAME.rb", and forget the index. I think I came up with a way to make this relatively pain-free. All it really requires is an extra check on the names like you mentioned on a save, and to track a list of scripts marked for deletion, since we don't want to actually remove the file until it is saved, but that shouldn't be too messy.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19898
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Script Structure
« Reply #19 on: December 04, 2011, 09:59:16 PM »
Ryex, what do you say on this? I think that this is an important enough matter that we should all agree on this.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.