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.
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.
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)
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!
Thank you BorisZ, Your help was very valuable!
You had right about If and Else If statements
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...
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.
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.
Just use functions, it's not really that important to have a goto if the language uses mainly function calling in my opinion.
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
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.
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
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.
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.
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.
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.
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).
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.
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...
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.
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.
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
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....
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?)
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.
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.
things such as SetPlayerCharacter are pre-set custom functions from within the AGS engine
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.)
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
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).
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...
take a lookie at this page.
http://www.agsforums.com/yabb/index.php?topic=15831.0
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.
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();
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.
Yeah,, that's the whole point in function based languages, at least to my understanding.
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?
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.
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).
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)
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 ;)
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.
Well yeah but I didn't feel like looking it up... the point was made though :P
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.
Obviously i believe you! :)