Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: miguel on Mon 22/09/2003 16:53:23

Title: newroom function problems
Post by: miguel on Mon 22/09/2003 16:53:23
I am having problems with this function, it seems that if statments are ignored and the engine jumps right to the newroom function,

example:

ran=Random(20);
if ran==10 display("blabla");
if ran==15 display("blabli");
if ran==20 newroom(2);

this is triggered when the player steps on a region, I tryed wait(1) to block it and return to the if statments but it doesnt work, thanks for the help
Title: Re:newroom function problems
Post by: Dan2552 on Mon 22/09/2003 18:42:39
I am not sure, but...
maybe the random number isnt 10,15 or 20??? ;)
i hope you figure it out. i am not sure the answer but I wanted to reply!
Title: Re:newroom function problems
Post by: Scummbuddy on Mon 22/09/2003 21:50:49
would you like to try it with paranthesies?

 if (my_counter == 5) {  
   my_counter = 0;
 }    


for example
Title: Re:newroom function problems
Post by: miguel on Tue 23/09/2003 00:57:46
basic mistake, sorry for the troubble

another one, I did look for it but couldn't find it, where do I SetGlobalInt? I mean, is it in the begining of the main script, room script, script header? I am asking this because I get this error:
Unexpected SetGlobalInt,
thank you
Title: Re:newroom function problems
Post by: Scummbuddy on Tue 23/09/2003 02:12:00
sorry, i was just kidding around and trying to be lighthearted.  

You should set up your global ints outside of any funtions, and perferably at the top of the script.
Title: Re:newroom function problems
Post by: Ishmael on Tue 23/09/2003 12:50:51
If you were changing the globalint, then there's something, like a } or a ) missing, so to help you with it, we'd probably need to see the script... :P
Title: Re:newroom function problems
Post by: miguel on Tue 23/09/2003 15:57:41
this is a simple script example, what am I doing wrong?

SetGlobalInt(3,3);
SetGlobalInt(30,2);

// room script file
int orcatk=0;
//
function region1_a() {
 // script for region1: While player stands on region
int ran=Random(1000);
if (ran==1000) {Display("ATENCION!!!");orcatk=100;}
if (ran==200) {Display("You feel stupid!");}  
}

function room_a() {
 // script for room: Repeatedly execute
if (orcatk==100) {Display("You are attacked by orcs!!!");NewRoom(2);}  
}

in room2 I need to check those globalints but the engine doesn't get to that point because when I try to test it, it says "unexpected setglobalint" refering to the first line of this script,
once again thank you

I did a search on (SetGlobalInt) and found that I should set my global ints on the Game_Start function and now it seems to be working, but I tought we should not set them inside functions?
I have a new question, how do I give an int the same value as a globalnt?

I mean,

int life=(GetGlobalInt(1)); //doesn't work, it gives the error, "expected value after ´=´

thank you

another question, how do I display a int value on a gui label? is it with @intname@, or %d.intname?, it doesn't work both ways,
thanks for the help or links to threads I can check
Title: Re:newroom function problems
Post by: Gilbert on Wed 24/09/2003 04:19:52
Where did you put those SetGlobalInt() lines? you CANNOT put them outside of any function like the variable definitions. If you want they be set once when room2 starts, put them in "player enters room for first time..." event function.
Title: Re:newroom function problems
Post by: miguel on Wed 24/09/2003 23:46:12
Got that Gilbot, thank you and everybody else
Title: Re:newroom function problems
Post by: Spyros on Thu 25/09/2003 21:44:20
Quote
int life=(GetGlobalInt(1)); //doesn't work, it gives the error, "expected value after ´=´

Try this
int life = GetGlobalInt(1);
Quote
another question, how do I display a int value on a gui label? is it with @intname@, or %d.intname?, it doesn't work both ways,
thanks for the help or links to threads I can check

SetLabelText (int gui, int object, integer)

Title: Re:newroom function problems
Post by: miguel on Thu 25/09/2003 23:35:49
thanks spyros,
it still doesn´t work,
int xp = GetGlobalInt(10); // gives the error  "expected value after ´=´
but It did work on the gui, also, is it possible to add values to globalints, not setting a value but adding a value to it?
thank you  
Title: Re:newroom function problems
Post by: Gilbert on Fri 26/09/2003 11:53:28
I'm not sure, but declaring a variable and assigning it with a function's value may not work.

So you may need to break the declaration part and the assignment part.

Do this.
On top of the whole script:
int xp;

Inside the functions you want to assign the value to the variable:
xp=GetGlobalInt(10);

To add a value to a Global Int, try something like:
SetGlobalInt(10, (GetGlobalInt(10) + 5));
(This line reads in the value stores in Global Int #10, add 5 to it and store it back, change whatever value you need in your own script.)
Title: Re:newroom function problems
Post by: miguel on Fri 26/09/2003 23:36:37
thanks a lot Gilbot, I hope I can help you some day,
I was really stuck here, I tryed ten diferent ways to add values to a global int and failed and I needed it to go on
thanks again to all