[ADVANCED] How can I use "import class from file [this] fileName []"?

Questions about GP commands and how to do things

Moderator: MSandro

Post Reply
MSandro
Posts: 162
Joined: Jul 26th, '17, 21:12

[ADVANCED] How can I use "import class from file [this] fileName []"?

Post by MSandro » Aug 26th, '17, 11:15

Hi, I try to make a molular project wich can import and export classes. Now I heave found my solution for the class-import but I don't know how I can get this block to work:
import class.PNG
import class.PNG (1.16 KiB) Viewed 10066 times
Also I heave the same problem with the "delete class [this] aClass []" block :(
delete class.PNG
delete class.PNG (1014 Bytes) Viewed 10066 times
I heave to find out wich block/variable I can insert in the "[this]" elements to make this blocks working.

Can anyone help me with this?

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: [ADVANCED] How can I use "import class from file [this] fileName []"?

Post by JohnM » Sep 16th, '17, 11:11

Both of those blocks are internal methods of a class called "Scripter" which is one of the panes of the GP IDE. The first ("this") parameter) has to be an instance of the "Scripter" class. These methods are usually invoked from an IDE menu that has a reference to the instance of the IDE's "Scripter"; they are not in a convenient form to be invoked from a script. (If you are modifying the IDE by, for example, adding another menu command, then depending on what menu you're adding it to there is probably some way to a reference to the scripter.)

I hadn't anticipated people writing programs to manipulate the IDE, but I can see that doing that could be interesting. A downside of writing such programs is that they would be dependent on the structure of the IDE, which is likely to change as GP evolves. For example, the top-level element of the current IDE is an instance of "ProjectEditor" and that has a method called "scripter" that returns its Scripter. But version 2 of GP might have a new class as the top-level or it might replace Scripter entirely.

However, if you're just doing a quick experiment and don't mind the fact that your code might stop working in some future release, here is a quick hack that will get you a reference to the IDE's Scripter:

Code: Select all

(scripter (first (allInstances 'ProjectEditor')))
To turn this text into a block, open a "Workspace" window, paste in and select the text, then invoke the "blockify it" command to turn it into a block. You can use that block as the 'this' argument of those the two blocks you found.

MSandro
Posts: 162
Joined: Jul 26th, '17, 21:12

Re: [ADVANCED] How can I use "import class from file [this] fileName []"?

Post by MSandro » Sep 16th, '17, 11:34

Thank you very much for the informations.
This is realy helpful.

Post Reply