Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: R4L on Sat 23/09/2006 19:03:09

Title: int shots; and inventory
Post by: R4L on Sat 23/09/2006 19:03:09
Hello, I seem to have another problem.

I have an inventory item in the game, and it's a Glock. It starts with 10 shots, so I put int shots = 10; in the global script, and for my glock, when the player tries to look at it, it says:

Display("Its my Glock, and it has %d shots left.",shots);

Well it doesn't seem to work, so I have placed int shots in Player looks at inventory item. This isn't really what I want, because I want to use RawDraw functions to show the number of shots left on the inv item.

Should I just use a global int to display the number of shots left on the Glock's picture and use it to keep track of the shots that are left?
Title: Re: int shots; and inventory
Post by: Gilbert on Mon 25/09/2006 02:49:59
Actually I couldn't quite understand your problem.

Quote
Display("Its my Glock, and it has %d shots left.",shots);

Well it doesn't seem to work

can you elaborate on how it "didn't work"?

Quoteso I have placed int shots in Player looks at inventory item.

if you declare the variable inside a function its change would be lost after the function had finished executing.

Also, remember, rawdraw works only on background at the moment, it may not be that suitable if you want to raw draw on an inventory sprite (there're tricks though).

Using a global int is not much different from declaring a variable in the global script, as long as you export the variable and import it in room scripts, it can be used in the rooms.
Title: Re: int shots; and inventory
Post by: R4L on Mon 25/09/2006 03:36:17
Well my GUI that I want to prnit it on is a pop-up model, so I could just check if that gui is on and run the rawdraw fuction. As for the int shots, I placed it in the global script at first, but I put it in Game_Start. Is that a problem?
Title: Re: int shots; and inventory
Post by: Gilbert on Mon 25/09/2006 03:38:46
But still rawdraw only works on the background at the moment, unless your GUI has a "hole" in it which see through on the bg in that part (or rawdraw it somewhere on the background, then capture it as a dynamic sprite)

No, don't do that, if you put the declaration in game_start() the variable will be local to game_start() only.
Title: Re: int shots; and inventory
Post by: R4L on Mon 25/09/2006 12:17:07
Damn, so I can't use the RawDraw functions? I'll have to find another way to do it, maybe a label would be best with a small font.

And I should be placing my int shots in repeatedly_execute right?
Title: Re: int shots; and inventory
Post by: Khris on Mon 25/09/2006 13:47:14
Not really, rep_ex is a function, too.
If you need shots to be accessible in all rooms, put this at the beginning of the global script, outside any function:
int shots;
export shots;
Then, in the header, put
import int shots;
Title: Re: int shots; and inventory
Post by: R4L on Mon 25/09/2006 13:50:49
Ah, see I forgot about imports and exports! Thanks alot for reminding me!