Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: SilverWizard_OTF on Sat 21/08/2004 17:54:44

Title: Go to... script command?
Post by: SilverWizard_OTF on Sat 21/08/2004 17:54:44
Hello
I would like to know if there is a "Go to" script command that i can use to AGS script editor, like this that Basic and Visual Basic have (and other languages).
   
I mean, to do something like:
                  if(my_counter==0) {
                        Go to(...);
                          }

Thanks for your time.
Title: Re: Go to... script command?
Post by: BorisZ on Sat 21/08/2004 19:11:12
You can call function instead of "go to" command (wich is rather obsloete even in visual basic, not to speak of C/C++, or pascal). You can simply declare global function, use it's header to make your room comunicate with it and then call it when you need it. Check your AGS manual about functions.
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Sat 21/08/2004 19:17:17
Hmm... that wasn't exactly what i wanted to say.
See this example:
     if(my_counter==0) {
         Display("You must wait one turn");
          my_counter==1;
          }
      if(my_counter==1) {
           //do something
           }

Here is the problem: I want character to wait one turn before the desired action is activated. But if i say "my_counter==1", it will immediately to "if(my_counter==1",  before executing the rest of the code.

   Any suggestions about that problem?
(Hey, a Go to command would be very nice idea)
Title: Re: Go to... script command?
Post by: BorisZ on Sat 21/08/2004 19:34:30
I must warn you that I am pretty new at AGS and I am not really sure what you are looking for but I can point you to a couple of possible solutions: 1. I dont think you can use my_counter==1 inside if loop. when == is used, it is only comparing, not adding (at least it is so in other programing languages), you should use my_counter=1 (if(my_counter==0) is OK, my_counter==1 is not). Another thing is that I think you should't use two if's,  but one if and one else if, the way you use it imediately changes variable and goes to another if. So: use if and else if and I think it will work. Forgive me if I missguided you in any way!
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Sat 21/08/2004 20:09:24
Thank you BorisZ, Your help was very valuable!
You had right about If and Else If statements
Title: Re: Go to... script command?
Post by: on Sun 22/08/2004 21:56:00
Or you could try:

a. Read the manual
b. Wait(int loops);
c. Re-read the manual
d. Search the forums
e. Read the manual

Or, alternatively, you could just try reading the manual that comes with AGS...
Title: Re: Go to... script command?
Post by: Hollister Man on Mon 23/08/2004 00:12:06
CJ has had several requests for GoTo, but its not really that important to most of us.  As you discovered, most of the time, it can be done another way.
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Mon 23/08/2004 20:34:52
Monkey,  i know VERY WELL what to do before i take a decision to post my problem here. Of course i had read the manual, but couldn't find that i wanted.
Hollister man, i disagree. I think a Go to command would be VERY VERY useful.
Title: Re: Go to... script command?
Post by: Gilbert on Tue 24/08/2004 02:56:32
Just use functions, it's not really that important to have a goto if the language uses mainly function calling in my opinion.
Title: Re: Go to... script command?
Post by: Kweepa on Tue 24/08/2004 03:33:40
Show us a situation where you think goto would be very useful and we'll show you an easy way to avoid it.

goto is generally a bit of a hack in a compiler, and often leads to less readable code, which is why its use is shunned.

Steve
Title: Re: Go to... script command?
Post by: Ishmael on Tue 24/08/2004 12:22:34
Got is useful in QuickBasic, where you don't use the functions that much.

PRINT "Blah balh balh"
IF blah = 1 THEN GOTO blah
PRING "bleh bleh bleh"
END

blah:
PRINT "Even more blah blah blah"
END

or something.... but in C it's easier to use functions and conditions.
Title: Re: Go to... script command?
Post by: BlackMan890 on Tue 24/08/2004 15:35:49
Quote from: Ishmael on Tue 24/08/2004 12:22:34
Got is useful in QuickBasic, where you don't use the functions that much.

PRINT "Blah balh balh"
IF blah = 1 THEN GOTO blah
PRING "bleh bleh bleh"
END

blah:
PRINT "Even more blah blah blah"
END

or something.... but in C it's easier to use functions and conditions.

you are not suposed to use goto in qbasic*, i know it and therefor use other things like: do ... loop and in this case, function

i know this because i create games in qbasic*.  In qbasic* you are strongly suggested NOT to use goto, only when you can't use anything else and i see that you don't have a reason to use goto and i think you never will

* qbasic = quickbasic
Title: Re: Go to... script command?
Post by: BorisZ on Tue 24/08/2004 19:07:43
There must be a good reason why using goto in most languages is obsolete. I think the main reason are problems with compiling wich goto may cause.
Title: Re: Go to... script command?
Post by: Snarky on Tue 24/08/2004 19:21:30
No, the reason is that it's bad programming practice, and contrary to the principles of structured programming (Pascal, C) and object-oriented programming (C++, Java).

In a modern programming language, it is never necessary and never any good reasons to use GOTO.

Although yeah, I can see how it could complicate the compiling as well.
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Tue 24/08/2004 19:55:43
A go to script command is useful for things like repeating the proccess of typing e.g. a name. In this case, if player by mistake typed numbers, then game should hive an error and return to this step.

Well, it is good to be added a Go to command for for anyone who wants to use it.
Title: Re: Go to... script command?
Post by: Snarky on Tue 24/08/2004 22:03:48
You can do what you describe easily with loops and/or functions.

Using GOTO leads to code that is disorganized, difficult to interpret and buggy.

It shouldn't be added because people should not use it, even if they want to.
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Wed 25/08/2004 13:17:56
Ok, ok. I think that we had told enough about "Go to" script command. I realise that it isn't so important (anyway, it isn't  terribe to JUST be added this, for anyone who might want to use it).
   By the way, you told something about "loop". Do you mean something like Basic's Loop script command? I haven't seen something like that to AGS sripting tutorial. (I hope you do not mean repeatedly_execute. It isn't so "effective" to use it more than one time).
Title: Re: Go to... script command?
Post by: Snarky on Wed 25/08/2004 13:59:09
A loop is a part of the code that is executed again and again until some condition is satisfied. AGS supports the WHILE loop, other common ones include FOR and DO...WHILE.
Title: Re: Go to... script command?
Post by: Dave Gilbert on Wed 25/08/2004 16:28:30
GOTO was used back in the old BASIC days when programs used line numbers.  If you wanted to move to a specific line within the program, you used the GOTO command.

10 PRINT "HI!"
20 GOTO 10

Would print "HI!" indefintely.

Ahh. Geek memories...
Title: Re: Go to... script command?
Post by: Albert Cuandero on Wed 25/08/2004 17:48:15
Yep, last time I used "GOTO", I had my - Sinclair ZX Spectrum 48K -  :D

(if any of the younger folks don't know, that's the thing with rubber keys from the mid-eightys)

I don't see any point in adding it to AGS - at least for me.
Title: Re: Go to... script command?
Post by: Ishmael on Wed 25/08/2004 18:35:42
Quote from: blackman890 on Tue 24/08/2004 15:35:49
you are not suposed to use goto in qbasic*, i know it and therefor use other things like: do ... loop and in this case, function

i know this because i create games in qbasic*.Ã,  In qbasic* you are strongly suggested NOT to use goto, only when you can't use anything else and i see that you don't have a reason to use goto and i think you never will

* qbasic = quickbasic

I was talking for myself, I've made text adventures with it, and in the I see no need for functioning everything.. I've made subs for repeated menu actiions and such, but the game part itself is IF's, PRINT's, GOTO's and labels in the simplest.
Title: Re: Go to... script command?
Post by: BlackMan890 on Wed 25/08/2004 18:59:13
first of all goto can be useless because you could use something else example:

choose:
print "the door was over there but you didn't have the key, what will you do?"
input "i will 1(break the door), 2(leave) or 3(check my soutcase)" done%
if done% = 1 then
  print "you broke the door but you fell down the stairs and died"
  goto dead
elseif done% = 2 then
  print "you left"
  goto room3
elseif done% = 3 then
  goto suitcase
end if
goto choose
room3:
code....


but what i would do is use subs so each room has its own sub
and the it would be much acurate example
this is sub room2

sub room2
print "the door was over there but you didn't have the key, what will you do?"
input "i will 1(break the door), 2(leave) or 3(check my soutcase)" done%
select case done%

case is 1
   print "you broke the door but you fell down the stairs and died"
    room2% = 5 '5 is what i use for dead

case is 2
   print "you left"
   room2% = 1
 
elseif done% = 3 then
  room2% = 2
end case

loop until done% = 5 or done% = 1 or done% = 2
end sub

then in main code would look like this:

call room2
select case room2%

case is 5
call dead

case is 1
call room3

case is 2
call soutcase


this is what i would use, i would have a sub for each room and using the main code to call them.
it would make it easyier to understand and shorter and would be easyier to change and add because everithing is in order

please forgive my english
Title: Re: Go to... script command?
Post by: Ishmael on Wed 25/08/2004 19:34:44
I make dead ends like those print's inside if's, but the continueing options have a got to put you to the new set of options....
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Wed 25/08/2004 21:08:31
I wave programmed with Basic too. From there i learnt Go to, and because i found it so useful command, i thought it would be fine to be added to AGS.
However, i realise that script code can be a bit complicated to be checked, as a result of using this command.
I do not insist any more. AGS provides us options for doing same things, using many different methods.  Also many experienced Basic users had told me too, that this command (Go to) is STRONGLY NOT RECOMMENDED. Anyway, maybe they have right. However, everything, under some circumstances, are useful. Even if a Go to script command in AGS!
            (I wonder, is it truth that AGS script editor is based on C++? I mean, if someone learns scripting in AGS, could he easily learn C++, and vice-versa?)
Title: Re: Go to... script command?
Post by: Ishmael on Thu 26/08/2004 08:32:34
Goto would be useful in AGS if you'd be making a text adventure, I see no other use for it. And, as I said, I used Goto in basic only to take the player to the next set of options, or to the help section, the quit section, the main menu... etc. as it is much more clear to me as making everything subs or functions.

Quote(I wonder, is it truth that AGS script editor is based on C++? I mean, if someone learns scripting in AGS, could he easily learn C++, and vice-versa?)

YES, it's stated in very many places already.
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Thu 26/08/2004 12:34:46
Hmm... yes, i think you have right about text-based games. I have not tried yet to create one, but i will try (even without  Go to script command!).
   It is very positive that AGS script editor is based on C++. However, i suppose that their command are totally different. I do not think that C++ has a command like "SetPlayerCharacter" !
   Anyway, AGS engine is versatile and i am sure that we can create with it anything we wish, even if we have to do it with a bit complicated method.
   
Title: Re: Go to... script command?
Post by: Mr Jake on Thu 26/08/2004 12:36:02
things such as SetPlayerCharacter are pre-set custom functions from within the AGS engine
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Thu 26/08/2004 12:49:35
Oh, i didn't knew this. It explains a lot of things. Well, thanks for your information.  This brings me the idea IF I CAN create a function like "Go to" by myself.

(From these i hear, i realise that C++ must be very powerful language.)
Title: Re: Go to... script command?
Post by: BlackMan890 on Thu 26/08/2004 17:55:22
also, when i learned qbasic, i found ags script very easy, so i would think that you would have none proplem learning C/C++ if you already know AGS script code, NOTE, in C/C++ there are Many Many Many more lines you have to learn
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Thu 26/08/2004 20:18:10
Thanks for the advice.
Well,  any idea of how can i create a Go to custom function? I imagine that i have to learn things that aren't written to AGS manual  (e.g. we would never be able to create a SetPlayerCharacter function. Custom functions that we can do are very limited in terms of what they can do).

Title: Re: Go to... script command?
Post by: Ishmael on Fri 27/08/2004 08:35:48
The AGS script code is not C, it's a C-like language. You don't, for ex. have FOR loops in it. So, you cannot create a Goto command, atleast not with the standard scripting. I don't konw about the plugin creation possiblities, you could always have a go at making a plugin for Goto in C, but I think it wouldn't turn up very usefull in the end...
Title: Re: Go to... script command?
Post by: Scummbuddy on Fri 27/08/2004 17:55:47
take a lookie at this page.
http://www.agsforums.com/yabb/index.php?topic=15831.0
Title: Re: Go to... script command?
Post by: Radiant on Fri 27/08/2004 18:21:10
Sample go to functionality:


int action;
while (1) {
  if (action == 0) {
    // do stuff
  } else if (action == 1) {
    // do other stuff
  }
   // etc
}


Now you can change the 'action' variable as a substitute for gotos.
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Fri 27/08/2004 20:26:27
Yes, i think that's a good approach of a Go to script command. Well done, Radiant.

Anyway, i think it is simpler and and with more effectiveness the idea of using Guis or Function.
Something like this:

int action;
if(action==0) GuiOn(1);   //Or     Function_doONE();
if(action==1) GuiOn(2); // or     Function_doTWO();

Title: Re: Go to... script command?
Post by: Edwin Xie on Fri 27/08/2004 20:33:38
Actually, I think that you don't need goto commands, you can always just type more simple things like GUIOn, SaveGameDialog, RestoreGameDialog show_inventory_window .etc... rather than typing unnecessary script like goto.
Title: Re: Go to... script command?
Post by: Ishmael on Fri 27/08/2004 21:14:42
Yeah,, that's the whole point in function based languages, at least to my understanding.
Title: Re: Go to... script command?
Post by: BorisZ on Sat 28/08/2004 23:07:24
Let's make it simple: If you used goto you would use it with line number:

goto 13

But as you noticed, line numbers are not important in object oriented languages, so what else could you do with goto?

goto Where

Considering Where was the title of your line. Isn't it the same as calling functions or subs or something like that (depending of language):

call Where

Considering where is name of your function.

Or am I wrong again?
Title: Re: Go to... script command?
Post by: Ishmael on Sun 29/08/2004 15:53:02
I think you're at the bottom of it. (The way to say.....?)

Thus QB IS object oriented, goto is useful, for me, when I make text based games/programs, but so far, nowhere else.
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Sun 29/08/2004 20:25:01
1 string password;
2 InputBox("The password is",password);
3 if(password==silver) // do things
4 if(password != silver) {
5   Display(WRONG!);
6    "Go to 1;"

It is usefull for something like that, so to do not be obligated to use functions for a so simple case.  But i agree that  using usually this command (Go to) it may make the script code a bit confused and a mess.

Using Function would be:

After fade in:

password_type();        //custom function (lines 1-2)
if(password==silver) // do things
if(password != silver) {
Display(WRONG!);
password_type();        //repeat the function
}


Ok, i got that.

BoriZ,  congratulations for your argumentation!  ;) 
(You should be proud with that,  because a Wizard is used to congratulate only people that really deserve it).
Title: Re: Go to... script command?
Post by: Alynn on Mon 30/08/2004 07:07:43
string password;

InputBox("The password is",password);
while (password!=silver){
   Display(WRONG!);
   InputBox("The password is", password);
}
//all other code here

In this instance it's a simple loop problem, you don't need to make recursive calls, which can be bad for the simple fact that recursive calls fill up the stack and will cause a stack overflow if too many wrong answers are given... (just FYI)
Title: Re: Go to... script command?
Post by: Ishmael on Mon 30/08/2004 08:08:55
Quote from: Alynn on Mon 30/08/2004 07:07:43
while (password!=silver){
Ã,  Ã, Display(WRONG!);
Ã,  Ã, InputBox("The password is", password);
}

while (StrCaseComp("silver",password) == 1) {

or however it goes ;)
Title: Re: Go to... script command?
Post by: Gilbert on Mon 30/08/2004 09:45:54
Better use:
while (StrCaseComp("silver",password)) {

As it's not guaranteed to be always 1 if they do not match:
Quote
Returns 0 if the two strings match, non-zero otherwise.
Title: Re: Go to... script command?
Post by: Alynn on Mon 30/08/2004 12:26:14
Well yeah but I didn't feel like looking it up... the point was made though :P
Title: Re: Go to... script command?
Post by: Pumaman on Mon 30/08/2004 21:18:03
Just to clarify, I will not be adding a GoTo command to AGS. As others have pointed out, it is very bad programming practice and is nowadays considered obsolete.

"else if" and "while" are far better ways of coding.

SilverWizard, just in case you don't believe us, I can tell you that in the 50000 lines of AGS source code, there is not a single "goto" statement.
Title: Re: Go to... script command?
Post by: SilverWizard_OTF on Tue 31/08/2004 19:31:43
Obviously i believe you!  :)