int shots; and inventory

Started by R4L, Sat 23/09/2006 19:03:09

Previous topic - Next topic

R4L

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?

Gilbert

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.

R4L

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?

Gilbert

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.

R4L

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?

Khris

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;

R4L

Ah, see I forgot about imports and exports! Thanks alot for reminding me!

SMF spam blocked by CleanTalk