Opening an external file in an AGS game?

Started by , Tue 30/03/2004 21:12:59

Previous topic - Next topic

wombat

Is it possible to, when you're half way through an ags game, to open a game made in another program (namely games factory pro)?

Hollister Man

Unless I am mistaken, ATM you would have to make a custom "launcher" program.  This could be as simple as a batch file (yourlauncher.bat) that would run your AGS game, then run your oter program, then run the AGS game again.  Its sloppy, but it would prolly work adequately.
That's like looking through a microscope at a bacterial culture and seeing a THOUSAND DANCING HAMSTERS!

Your whole planet is gonna blow up!  Your whole DAMN planet...

Scummbuddy

That would be the closest thing you can do. The only other program that Ags can launch from within itself is another ags game.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

ElectricMonk

#3
You could create a batchfile that looks something like this.

(Commands in brackets mean that I know what the program is supposed to do, but I don't know the command...)


(create a text file named "check.txt" that contains the number "0")
AGSGAME.EXE
OTHERGAME.EXE
(change the number in the "check.txt" file to "1")
AGSGAME.EXE
(change the number in the "check.txt" file to "0")


Within the AGS game, you'd have to do the following:

When you break off the game to start the non-AGS game, execute a script similar to

SaveGameSlot (30, "dummygame");
QuitGame(0);


When you start it (again), you need to tell the game to continue where you left off. So somewhere near the function game_start (or possibly in the start script of your first room) execute a script like:

(Read the contents of the "check.txt" file into a variable, say "secondround")
if (secondround == 1)  RestoreGameSlot(30);


I'm not entirely certain how to create text files on the fly in batch files, but I think it's possible. It's been a long time since my batch file writin' days...
Perhaps AGS can also create short text files with FileOpen, I don't know. And I don't know how it will deal with files that need to be overwritten.

Well, that's my two cents anyway...

Radiant

For the batch files, try

ECHO 1 > TEXTFILE

And AGS can do FileReadRawChar () to check what's in the file.

wombat

Thanks for all the help guys, but im a real newbie, and I dont have a clue how to create the batch file you described.
Could you please help me out?

Thanks (sorry) :-)

Ishmael

#6
To create a batch file? Try this: go to the compiled folder of your game, right click, select New, and select Text File. Then, open the text file up and instert into it:

echo 0 > check.txt
agsgame.exe
othergame.exe
del check.txt
echo 1 > check.txt
agsgame.exe
del check.txt

... replaceing the agsgame.exe and othergame.exe with the proper executable names.

Work surely in all other OS' then XP, I'm not so sure 'bout XP just yet...

(Like TK originally said before I edited it for continuity, do not create new posts to continue a conversation on the same subject.)
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

ElectricMonk

...and then save the whole thing as "filename.bat".

Ishmael

I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Ginny

#9
Hey, that's real interesting! Where can I learn more about this batch "language"? I see potential :D
Try Not to Breathe - coming sooner or later!

We may have years, we may have hours, but sooner or later, we push up flowers. - Membrillo, Grim Fandango coroner

wombat

Thanks for all the help, and sorry bout screwing up in the forums - ill remember bout keeping the same topic.

Also, just cos im a member now, doesnt mean im any less new!!

thx

the wombat

wombat

#11
Ok, i tried the batch file thing you said, and i typed this into the text file:

echo 0 > check.bat
spygame.exe
shootergame.exe
del check.bat
echo 1 > check.bat
spygame.exe
del check.bat

In the ags game (spygame.exe) i typed the script (i'm trying to exit the ags game  from a dialog):

else if (param ==20) {
  SaveGameSlot (30, "SaveGame");
  QuitGame(0);

But when I reach the point in the game that it is meant to quit, it quits, saves, but does not open the external game (shootergame.exe). I'm not particularly surprised at this as I have put no script into ags telling it what to do, but I am unsure what script to write.

SSH

You need to run the .bat file, rather than the AGS .exe file...
12


ElectricMonk

Simply doubleclick on the .bat file like you would on a normal .exe and it should run.

TerranRich

#15
Lesson:

Windows supports four file extensions that can be executed as programs:

.EXE - Regular EXEcutable
.BAT - BATch file, with DOS commands inside a file that are run in sequence
.COM - DOS COMmand file, like an executable specially for DOS
.PIF - Program Initiation (?) File, like a Windows version of a batch file, with extra options

:)
Status: Trying to come up with some ideas...

wombat

Okay, so ive tried opening it up, an MSDOS window comes up then closes again real quick. when i go to edit the .bat file in notepad all it comes up with is 0. is this because i have xp or is it because i just suck at scripting?

also, how would i create a .pif file to do the same thing, and where can i find information on all of this?

Sorry i suck so much...

wombat

Ginny

I found a page on batch files that seems interesting:
http://www.computerhope.com/batch.htm
Why did the file display zero?
Try Not to Breathe - coming sooner or later!

We may have years, we may have hours, but sooner or later, we push up flowers. - Membrillo, Grim Fandango coroner

wombat

i tried that website, and did what it said (which worked) but i could never seem to get it to start up any programs. I'm getting really annoyed with myself now. I need a definitive way to swich between my two files - oh dammit, i just realised that my ags game is not one file, it is loads of files, on for each room etc. Does this make it harder to switch between programs considering there is no "agsgame.exe" to switch from or to?

Oh god im drowning in the complexity of my first game!!! i dont know how i'm going to finish... im still on level one

Ginny

#19
I think you should put the batch file (aswell as the other game .exe made in a different program) in the compiled folder, where there is only one game file.
(That is unless I've missed something and you already have).
Try Not to Breathe - coming sooner or later!

We may have years, we may have hours, but sooner or later, we push up flowers. - Membrillo, Grim Fandango coroner

ElectricMonk

#20
Interesting... I'm trying to write a simple "save - run another exe - restore" test game, and as soon as I run the .bat file, it tries to run each program after another without waiting for the previous one to end, which also means by the time the first AGS game starts, the "check.txt" is already deleted again.
Is that because I'm not working in "real" MS-DOS mode?

EDIT: Even worse - The number I'm trying to read from the text file gets read wrong.

I use (in the first room, AFTER fadein for convenience right now, so I can read the result):

int checknumber;
int handle = FileOpen ("check.txt", FILE_READ);
checknumber = FileReadRawInt(handle);
FileClose (handle);
string buffer;
StrFormat (buffer, "%d", checknumber);
Display(buffer);  // show the number you've read in the file
if (checknumber ==1) RestoreGameSlot(30); // if it's 1, restore.

The file "check.txt" at the moment contains nothing else than the number "1" in pure ASCII format. And yes, it's in the "Compiled" folder.

Apparently this whole idea is not as easy as I had previously thought. Any ideas, anyone?


EDIT #2:

At least I solved the "stupid batch file, wait until the first program has finished!" problem now:

echo 0 > check.txt
start /wait testrun.exe
start /wait othergame.exe
del check.txt
echo 1 > check.txt
start /wait testrun.exe
del check.txt

wombat

#21
Ok, ive made sure that everything is in the correct place, but the same thing is still happening. What you're telling me should happen is that I should be able to double click on the batch file, it will open up my ags game, when the ags game quits it will open up the other game, and when that quits it should re-open my ags game.

Well thats not happening. ive written the exact code that i showed in the previous post, and all thats happening is an ms-dos window flashes open and closed once, and then nothing happens. I dont even get either program opening up. When i check the batch file all that appears is a 0.

Can anyone find an error in my scripting?

[EDIT]

after just reading the last edit from electric monk, i am even more confused. Should I be putting that kind of script into my game? And also, what can you tell me about file handles, i seem to have not found that bit in the tutorial...

finally, can i make whether you win or lose the game (not ags game) affect what happens when you come back into ags?

[EDIT #2]
Could electric monk (or anyone else who happens to see this post) write me a script for my game that would open the batch file (like electric monk did in last post except using "spygame.exe" as the ags game, "shootergame.exe" as the other game and "check.bat" as the batch file. i am confused

strazer

Quoteas soon as I run the .bat file, it tries to run each program after another without waiting for the previous one to end

Using CALL will wait for a batch file to finish before continuing, I don't know if it works with exe's:

echo 0 > check.dat
call spygame.exe
call shootergame.exe
del check.dat
echo 1 > check.dat
call spygame.exe
del check.dat

?

ElectricMonk

#23
Quote from: wombat on Sat 03/04/2004 20:48:52
ive written the exact code that i showed in the previous post, and all thats happening is an ms-dos window flashes open and closed once, and then nothing happens. I dont even get either program opening up. When i check the batch file all that appears is a 0.

Can you put the batch file up on a website somewhere so I can take a look at it? Normally, you should be able to open it with notepad and see your script, not just a 0.


Quote
after just reading the last edit from electric monk, i am even more confused. Should I be putting that kind of script into my game?

Something like that, anyway. I'm not sure about it myself.

Quote
And also, what can you tell me about file handles, i seem to have not found that bit in the tutorial...

I'm pretty much a newbie myself, I just took the info from the help file and changed the names of the variables. No idea why you need that "handle" stuff.

Quote
finally, can i make whether you win or lose the game (not ags game) affect what happens when you come back into ags?

That depends whether your other game is able to export some sort of text file that, again, must then be read by AGS in order to make that decision.


EDIT:
Strazer: "call file.exe" doesn't work, at least not in my Win98 environment. It still starts all of them at once.
"start /wait file.exe" works though.

ElectricMonk

No disrespect, but I don't think this thread should be archived yet as it's not yet resolved.

When I use
Quote
int checknumber;
int handle = FileOpen ("check.txt", FILE_READ);
checknumber = FileReadRawInt(handle);
FileClose (handle);
string buffer;
StrFormat (buffer, "%d", checknumber);
Display(buffer); // show the number you've read in the file
to read the number in a text file called "check.txt" that only contains the number "1", I get "-1" displayed as a result. The same happens when the file contains "0".
Anyone know why?

foz

Can i ask why you want to launch a gamefactory game while playing an ags game...?

wombat

<tee hee>

the reason is that in ags i cant find any way to create a ... kind of... 'minigame' that i can make the user play in order to get a certain item. If you know any more about this than i do, please reply... or it may be on a different thread...

ElectricMonk

#27
Also, I'm sure many people will find it running other .exes from AGS handy - for flash animations, for example.

Personally, the whole "reading stuff from external files" is an important issue for me as it may well crop up in future projects.

Pumaman

FileReadRawInt reads a raw 32-bit integer from the file, not a number in ASCII representation. The easiest way to do what you want would be to write the letter 'A' to the file, then use FileReadRawChar to check it.

ElectricMonk

Thank you, now it's working! ;D

To sum up:

The start.bat file that goes into your Compiled folder:
Quote
echo A > check.txt
start /wait agsgame.exe
start /wait othergame.exe
del check.txt
echo B > check.txt
start /wait agsgame.exe
del check.txt

(BTW, this means you manually need to put a "check.txt" with the proper contents in your Compiled folder if you want to test the game from inside the AGS editor, since the .bat file deletes "check.txt" at the end.)

The action to quit the game and save the position at the end of the first run:
Quote
SaveGameSlot(30, "inbetween");
QuitGame(0);


In the Global Script, in function game_start(), the script to make AGS restore the position in the second run:
Quote
{
string checkchar;
int handle = FileOpen ("check.txt", FILE_READ);
StrFormat (checkchar, "%c", FileReadRawChar (handle));
FileClose (handle);
if (StrCaseComp(checkchar, "B") ==0) RestoreGameSlot(30);
}

(Which only leaves me with the newbyish question: What are raw 32-bit integer numbers, and how do I convert them to the decimal system?) :-[

mätzyboy

#30
A raw 32 bit integer is an integer (no decimals) with 32 bits of data (possibility to store numbers from 0 to 2^32).

Your actual question is what is ASCII. ASCII is a standard for representing alphabetical characters using numbers. For example the letter A is represented as the number 65 in decimal numbers or 1000001 in binary numbers. Check http://www.neurophys.wisc.edu/www/comp/docs/ascii.html for a complete translation guide...

With a little thought you'll see that converting ASCII to numbers (given that you KNOW you will be converting a number between 0 and 9 NOT a letter) is to subtract 42 from the raw integer containing the imported asciicode...

Hopefully I managed to make things a little more clear  :)

Pumaman

Yeah, the FileReadRawInt function is designed for reading binary files output by other programs. It's not useful for reading in text files.

Hollister Man

I have constructed a *semi* functional AGS launcher that currently runs two different AGS games alternating, but isn't quite working right.  I am trying to make it as transparent as possible, but it will also have a GUI available. 
With luck, it will be working sometime this weekend.  I'm just having trouble figuring out why it is still running the batch file even though I've overwritten it already. :)

We're planning on including it with DQ3, for use with the sub-game structure.  This way, all units can be viewed and dissected separately, but can still be played as a whole. 
That's like looking through a microscope at a bacterial culture and seeing a THOUSAND DANCING HAMSTERS!

Your whole planet is gonna blow up!  Your whole DAMN planet...

Gankkizz

Can you read a file in batch?

First run a batch file, write "0" to file.dat, run an AGS game, write "1" to the file, exit, read the file in batch and run another game if the number has been changed...

Snarky

Quote from: wombat on Sat 03/04/2004 20:48:52
all thats happening is an ms-dos window flashes open and closed once, and then nothing happens. I dont even get either program opening up. When i check the batch file all that appears is a 0.

Wombats, I know why this is happening. Let's have a look at your script:

Quote from: wombat on Thu 01/04/2004 20:45:42
echo 0 > check.bat
spygame.exe
shootergame.exe
del check.bat
echo 1 > check.bat
spygame.exe
del check.bat

I bet you stored all of this in a file called "check.bat". What happens is that when you run it, on the very first line, "echo 0 > check.bat", it writes "0" to the file "check.bat"... itself! So all the following commands are overwritten, and nothing more happens.

Try changing the commands to say "echo 0 > check.txt" (or "check.dat", or whatever) etc., and naming your batchfile "rungame.bat". That way you won't be confused.

SMF spam blocked by CleanTalk