Moneybag on the inventory GUI?

Started by Minimi, Sat 27/09/2003 21:26:34

Previous topic - Next topic

Minimi

For my new game, I want to make something in the way like in Zelda, that you have a moneybag, besides your inventory, with a number besides it, wich shows how much coins you have. It's for me still pretty misty about the GUI's so I actually don't know if this should be at beginners forum.

But so I want to show how much coins I have, I guess by showing a global value, but how do I make this?

Timosity

#1
You could try something like this: (I did something in one room that had a count gui going, you might be able to use it to incorporate it into a global function, you may have to import things into the global header for it to work throughout the game in all the rooms) That's an experiment for you to work out,  but here's how to do it in a room

This example uses GlobalString(10) & GUI(5)

*in the start:
function game_start() {

SetGlobalString(10,"0");

}

*Start off making the GUI you want, make it as a "Normal" one. create a Label with the font you want and start with the text "0"



*script for when you get a coin(eg. when you pick up object or however you acquire it)

first at top of script:
int coin; // this is for each coin you pick up
string coincount; // this is for a conversion to string for display in GUI


coin++;
StrFormat (coincount, "%d", coin); // converts int to string for use in gui
SetGlobalString(10,coincount); // sets the string coincount to a globalstring

then in the room repeatedly execute

string getcoin;
GetGlobalString (10, getcoin);
SetLabelText(5,0,getcoin); // this puts the number in the GUI

**so whenever the 'int coin' in the room is increased by 1 the GUI will display the current number of coins collected.

I think that's about all you have to do for it to work in one room.

To make it work throughout the game, experiment with making some of these things global functions and then importing them into the script header.

I don't know if it will work but there's a start to get you on the right track I hope.

~Tim

Minimi

Thanks timosity, I got it working for one room, but now I need to have it in the whole game, like zelda you know!... can someone plz help me on how to make this in the global script?

Gilbert

Actually I'll use a global INT instead of the hasse of global strings for this.

Idea:
Choose a Global INT for storing the current money amount. For definiteness I'll choose 10 here.
Now say, you need to display it in label #0 of GUI #5 (replace whatever appropiate yourself).

On top of GLOBAL script, add:
string montemp;

And in repeatedly execute of GLOBAL script, add:
StrFormat(montemp,"%d",GetGlobalInt(10));
SetLabelText(5,0,montemp); //update label text



Then whenever you want to change the value of amount of money in the game, just modify the Global INT 10 (you can do this in whereever appropiate, no matter in room or global script). For example:

To add 10 to money, just do:
SetGlobalInt(10,GetGlobalInt(10)+10);

To subtract 10 from money, just do:
SetGlobalInt(10,GetGlobalInt(10)-10);
(Of course, you may check whether it becomes negative, ie you may script it so it check if the player has enough money to pay, etc., but this is trivial I think)

To set the money to a specific amount (eg set it to 150), just do:
SetGlobalInt(10,150);


Ishmael

Just curious...

Can you do

set-globalint 10 + 2

or

set-globalint 10 - 2

in dialog script?
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Gilbert

Dunno, but probably not, why not try it out? ;)

Ishmael

A good question.......

Hmm.....

Well, mainly because I'm lazy right now.

;D
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

SMF spam blocked by CleanTalk