2019-05-03 20:35:46

So, I am not sure how this might be done, but it might be possible to, or is almost certainly possible to, either package Python and modules in a BGT pack file, then use python37.dll or something like that to run Python code.
I think that there is some kind of eval function you could use, or someone could write a python script, compile it with Cython, make an executable, and that script then takes lines of Python code.
Do you think this would be a good idea?
It'd certainly be cool to meld BGT and Python, Python can probably download files much more easily than BGT.

My tactical battle scripts: https://www.dropbox.com/s/dzsmqv2pgqvu1 … h.zip?dl=1
Currently, one of my favorite games is Trimps.
So I'm the Trimper Trooper!

Thumbs up

2019-05-03 23:34:31

I mean, if someone could write a wrapper for python that allows a lot of bgt's things like sounds, witch we have, screen reader support, and other things, then yeah, I'd probably use it.
But as of now, without a wrapper like that, no.

yo! so I'm working on programing, it's really hard. But I'll tell you where you can contact me if your stupid enough to do so.
Contact information:email: [email protected]
Skype: Brennan Draves
I'm usually found on online games, chatting, and being warned bye admins for talking to much, f**k you admin!

2019-05-04 00:10:57 (edited by Ethin 2019-05-04 00:11:40)

I would not do this. Running Python code from BGT is far more complicated than you think -- go check out the Embedding Python in an application documentation section in Python's docs. Its already incredibly hard in C and C++; its going to be a shit ton harder in BGT especially if you want to catch Python errors.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

2019-05-04 01:07:56 (edited by Lucas1853 2019-05-04 01:09:01)

Um... Oh my god, no. I'm not really sure what you want (to access members of your BGT program from Python?) but it will most likely never happen.

Sincerely,
Lucas.

Thumbs up

2019-05-04 18:57:10

One word answer?
No!

My name is Inigo Montoya. You killed my space bar. Prepare to die!

http://l-works.net

2019-05-04 20:02:04

There might be another easier way to do it.
First, compile an app with pyinstaller, that imports all the modules and have it check a file like 5 times per second.
If something is in that file, execute it as Python code.
Then you can redirect stderr and stdout to another file, and BGT can read those.
Not particularly great, but it'd certainly work and it might not cause too much lag.

My tactical battle scripts: https://www.dropbox.com/s/dzsmqv2pgqvu1 … h.zip?dl=1
Currently, one of my favorite games is Trimps.
So I'm the Trimper Trooper!

Thumbs up

2019-05-04 20:08:53

Again, no! Never! That is such a hackish solution -- I don't know why you'd ever want to integrate Python and BGT in any way. That's just asking for trouble.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

2019-05-04 20:46:19

It'd probably be easier to connect them via UDP. But why?

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

2019-05-06 00:21:01

Actually @8 I'm not sure that would be easier, I don't know if anyone has successfully recreated philip's enet settings in another language to communicate with the BGT's network object. Please feel free to correct me though. In any event, I see no reason why you'd want to do this. You could learn much of python in the time it would take you to get something like this working, and there are just sooooo many issues you'd run into. You need a lot more than python37.dll to make this work unless all you want is python builtins and even that would be iffy. You wouldn't even have the os module. Now, if we could make python and enet work together, the 1 time I could see this actually being really cool is making a BGT game client, then making a multithreaded server application in python and hosting it on a cheap linux box. That could be cool. If it wasn't for the av thing, BGT has all you'd need for a client, and so if a game central server could be written in python that could open up many possibilities. But then again you could write a cross platform client in python that would be even better. In any case, you don't really gain much. Also, you couldn't read BGT properties or call BGT functions from python. If you could figure out a way to do this that's great you should show me, but I don't believe it is possible to the magnitude you want. You similarly can't call BGT functions as callbacks from C DLL's because the functions are only registered with angelscript. I may mess with finding the address of the angelscript call function in the BGT executable and try to see if I can trick it into calling my function, but I don't think I'm that smart big_smile As for using pyinstaller? Dude every time you run an onefile pyinstaller executable, loads of files are extracted from temp. In order to read stdout and stderr output in BGT, you have to use cmd.exe as a proxy and use > output.txt or | clip and that's just impracticle. If you want something that downloads files faster, get BGT working with curl if you must though I'd avoid it, or find a C library that can do what you want and use BGT's dll functions.

I am a web designer, and a game developer. If you wish see me at http://www.samtupy.com

2019-05-06 01:19:43

I agree with 9 (though enet could probably be used in C++ or PyEnet with BGT, though that would need some testing). Plus, doing this would be incredibly complicated if not impossible. Pythons C API is hard enough as is, we don't need DLL abstractions over it to complicate things.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

2019-05-07 02:34:25

Here's a short example for those wanting to use BGT and Python together.
const string script = "import win32api\nwin32api.MessageBox(0, \"Hello from Python\", \"Hello\", 0)";

void main()
    {
    library python;
    python.load("python37.dll");
    python.call("void Py_Initialize();");
    python.call("int PyRun_SimpleStringFlags(char *, int);", script, 0);
    python.call("void Py_Finalize();");
    python.unload();
}

Thumbs up

2019-05-07 02:58:33

ok, you managed to use python.
now, considering that you need to use many scripts and imports from python then how you'd go for it?
yes it is possible to go with pyenet and then using bgt with eNet, but I don't think it is the recommended way.
My whole idea is, put bgt away and use python. what does bgt have, that python hasn't?
sound, keyboard handling, everything exist for you!.

bitcoin address: 1LyQ3hziMC2DTnCtgM3V1zfuZ73P3CYT9P

2019-05-07 04:17:43

@11, I don't even think that would even work. What about error handling? What about retrieving Python structures and passing them back to C and then into BGT. Gross. I just don't understand why you would ever want to do this - it would be just as mad as trying to implement the win32 API into BGT.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

2019-05-07 16:48:31 (edited by thggamer 2019-05-07 16:51:41)

@13 It's possible, but not practical. A very big workaround would be needed to do this with BGT's library object. If you use C between Python and BGT, things get easier, but only a bit.
However, I agree with @12. I would only use this if I had a big BGT project and I needed to add more features that weren't possible with BGT.

Thumbs up

2019-05-07 17:59:13

@14, uh... no, man, I just wouldn't do it no matter how big your project is. Just use Python if you want it so bad. Don't try FFI when the API to use it isn't even known for its stability or ease of use.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

2019-05-07 19:39:37

lol you can't do much with just python37.dll. You could probably get it to work with a lot of hacking, but it's just so not worth it. The only reason you were able to import win32api is because you had it installed. It wouldn't work if you distributed python37.dll with your game. Though to clear something up, @Ethin making the windows API work in BGT is actually duable, and if you get the code working practicle, but it's just not worth writing the code. Despite what people want you to believe reading DLL structures in BGT is more than possible. Theoreticly you should be able to write them as well, I just have to figure out how to get the address of strings. I can already write structures with basic ints and stuff, and BGT has a function called string_create_from_pointer that can take a 4 byte pointer and convert it to a BGT string. If I wanted to do it I'm sure I could wrap sockets in BGT. And it would even be responsive. The only reason I wouldn't do it is because it's just a lot of code to write when I already have python. But if the code was written, it would run with almost 0 extra overhead. That can be said about most of the windows API as well, and that's excluding the functions that can be called with BGT without the need to read structs, which is quite a lot.

I am a web designer, and a game developer. If you wish see me at http://www.samtupy.com

2019-05-08 00:27:30

@16, what about 8 bytes of data like int64_t?
or something like ptrdiff_t which is different in some systems?
or a void* which you can pass a pointer to int, or a pointer to a structure to it?
what about c callback functions?
@14, if you are asking me, don't go for it at all.
python has everything you need.
even it has support for windows api by using pywin32
you might think that, bgt has something which python hasn't, and you can use it to write a big project, but I have to tell you that you are in the wrong direction.

bitcoin address: 1LyQ3hziMC2DTnCtgM3V1zfuZ73P3CYT9P

2019-05-08 16:55:03

@17, the only point you have is C callback functions, that would be extremely difficult to set up, so functions that use callbacks could hardly be wrapped I believe. Maybe there is a way, I just haven't sat down and attempted to figure it out. With BGT's library, you can pass an int of 4 bytes, or even a string of 8 bytes. It's typically pretty malleable with BGT, if the handle to something is a void*, you can save that in BGT as a 4 byte int. For structs, you can read them as char*.

I am a web designer, and a game developer. If you wish see me at http://www.samtupy.com

2019-05-09 00:17:31 (edited by visualstudio 2019-05-09 00:18:37)

so, @18, how do you translate this in bgt?

typedef void (*callback)(int p1, size_t p2, const char* p3);
typedef struct {
union {
int16_t a;
const char* c;
}type;
callback cb;
void* userdata;
}a;
void func_1(a* p1, void* userdata);

considering that it has unions (which accesses the same memory address using different types)

bitcoin address: 1LyQ3hziMC2DTnCtgM3V1zfuZ73P3CYT9P

2019-05-09 06:22:52

So I have never seen a union before this. However, when reading a struct, you would write it in the BGT DLL call as a char* and read the struct as a string of bytes. Thus, to read something from the same address twice, you just access the same bytes from the string. It can be somewhat tricky to deref pointers, but for example with strings, we have the string_create_from_pointer function to do it for us. So if there were 4 bytes that could be read as a string and an int, you would run code that uses bitwise operations to convert the 4 bytes into a true int. Then you can both pass it to string_create_from_pointer and show the raw int in an alert box. Remember, all structs are once they are packed are a series of bytes. We can read these bytes as a BGT string to turn addresses that are shown in the struct to ints, then access them or pass them to other DLL functions. I unfortunetally can't give you code as I've never seen a union before, so I'll have to see what the byte sequence for one looks like and learn exactly how they work, but I would imagine it would be duable. Furthermore, I have not written any kind of include to read structs, I just have a messy implementation at this time that reads 4 chars from a string, converts them in an int, reads a byte and converts it to a bool, reads 4 bytes and converts it to a string with string_create_from_pointer, etc. So there is currently no pretty code that does it. However at some point I may attempt to make a struct class where you can call an add_value function, or pass a string representation of the fields to the classes constructor similar to what you would do in python. From what you've described of unions though it looks possible, though I have not messed with them myself.

I am a web designer, and a game developer. If you wish see me at http://www.samtupy.com