SOLVED: Still need a solution for adding up and message

Started by barefoot, Sat 22/01/2011 10:40:15

Previous topic - Next topic

barefoot

Hi

I am desperately trying to find a way to resolve a game problem I am having.

I've looked at various ways within my knowledge but not to much avail at the moment.

I still need a way to determine what inventory items the player has and then give the player a total price for what he has... This is done in the Fence Room...

Whatever items the player has the fence will say what he has and give a total price.

Its an 'add up' and a message solution i'm looking for.

Example if the players has Wallet, Credit cards, CD player then the fence may say (after checking what you have) "You have Wallet, Credit cards, CD player" "I'll give you $300"


Could the be done through a points system with each item having  a points value then in the fence room the fence will say something depending on your points total?

Hope you understand and can help me with a solution that is easy to integrate.

cheers for any help

barefoot







 
I May Not Be Perfect but I Have A Big Heart ..

skuttleman

Something like this might help you. It doesn't take into account the inventory items are worth different values, and it assumes that every inventory item is worth something, but hopefully it will be enough to get you started.

Code: ags

int inventorycounter=1, money=0;

cFence.Say("Let's see what items you have.");
while (counter <= Game.InventoryItemCount)
{
  if (player.HasInventory(inventory[counter])
  {
    cFence.Say("You have the %s.", inventory[counter].Name);
    money = money + 100;
  }
  counter ++;
}
if (money == 0) cFence.Say("You don't have anything.");
else if (money == 100) cFence.Say("I'll give you $100 for it.");
else cFence.Say("I'll give you $%d for everything you have.", money);

barefoot

Cheers skuttleman

every little helps as they say....

Hopefully this topic will be expanded until i get a full result and can implement it into my game..

cheers

barefoot

I May Not Be Perfect but I Have A Big Heart ..

Dualnames

#3
Code: ags

cFence.Say("Let's see what you got !");
 if (inventorywindow.ItemCount==0) {
     cFence.Say("You got nothing.");
 }
 
else {
 int i; totalvalue, itemid;
  while (i!= inventorywindow.ItemCount) {
    itemid=inventorywindow.ItemAtIndex[i].ID;
    totalvalue=+inventory[itemid].GetProperty("moneyvalue");
    i++;
  }
cFence.Say("Total value is %d $", totalvalue);
}

There may be parse errors or small continuity stuff that I missed. And you need to create a property called moneyvalue with default value 0 and the property being a number. All you need to do is just clarify each item's value and you're set.

the inventorywindow is the inventory gui control of your Inventory GUI. If that makes sense.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

barefoot

#4
Hi

cheers Dualnames

I have created a global variable called moneyvalue and have set it to Int with value of 0..  I need to work from there...?

I use gInventory as my Inventory window.

Your code does give a bit of an error:

GlobalScript.asc(1018): Error (line 1018): '.ItemCount' is not a public member of 'GUI'. Are you sure you spelt it correctly (remember, capital letters are important)?

Code: ags

function cfence_Talk()
{
cfence.Say("Let's see what you got !");
 if (gInventory.ItemCount==0) {
     cfence.Say("You got nothing.");
 }
 
else {
 int i; totalvalue, itemid;
  while (i!= inventorywindow.ItemCount) {
    itemid=inventorywindow.ItemAtIndex[i].ID;
    totalvalue=+inventory[itemid].GetProperty("moneyvalue");
    i++;
  }
cfence.Say("Total value is %d $", totalvalue;);
}
 }



cheers

barefoot


I May Not Be Perfect but I Have A Big Heart ..

Dualnames

It's not the GUI, it's the GUI control. Gui controls have types,like buttons, labels, textboxes, listboxes, inventories. You need to set up the inventory gui control and not the gui itself.

Also re-copy the code again from my post, cause I found a small parse error as well.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

barefoot

cheers dualnames

not sure how do the gui controls as suggested and i have put it where the fence talks as per script.

I get:

GlobalScript.asc(1019): Error (line 1019): '.ItemCount' is not a public member of 'GUI'. Are you sure you spelt it correctly (remember, capital letters are important)?

Maybe  im  missing something..

maybe you could elaborate.

cheers dualnames

barefoot

I May Not Be Perfect but I Have A Big Heart ..

Khris

If you want to use Dualnames' code, you have to replace "inventorywindow" with the scriptname of the InventoryWindow GUIControl, NOT the name of the inventory GUI itself.

Also, this is the third thread about a problem I pretty much solved in the first one; I even rewrote the code so you can display the message any time you want; the total sum is saved in an int variable; what else could you possible need to integrate this into your game?

So, everybody else, please check out my post from several days ago.

barefoot

Hi Khris,

i understand what you are saying...

This is a new script thing for me and i'm having a little trouble putting it in..

i clicked on the inv window and it says invCustomInv would this be the control dualnames spoke of?

I know its a pain but i don't intend to give in until a solution is found.. and i do thank you for your comments khris.

I will endeavour NOT use different posts.

regards

barefoot
















I May Not Be Perfect but I Have A Big Heart ..

Dualnames

Quote from: barefoot on Sun 23/01/2011 16:37:27
i clicked on the inv window and it says invCustomInv would this be the control dualnames spoke of?

Quite possibly.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

barefoot

#10
Hi

The script dualnames gave seems to accept the following:

Code: ags

function cfence_Talk()
{
cfence.Say("Let's see what you got!");
 if (invCustomInv.ItemCount==0) {
     cfence.Say("You got nothing.");
 }
 


But not this bit:

Code: ags

else {
 int i; totalvalue, itemid;
  while (i!= inventorywindow.ItemCount) {
    itemid=inventorywindow.ItemAtIndex[i].ID;
    totalvalue=+inventory[itemid].GetProperty("moneyvalue");
    i++;
  }
cfence.Say("Total value is %d $", totalvalue;);
}
 }


Error:
Failed to save room room1.crm; details below
room1.asc(152): Error (line 152): PE04: parse error at 'totalvalue'

But has accepted this amended script in compiling but error in game:
Code: ags

else {
 int i= totalvalue, itemid;
  while (i!= invCustomInv.ItemCount) {
    itemid=invCustomInv.ItemAtIndex[i].ID;
    totalvalue=inventory[itemid].GetProperty("moneyvalue");
    i++;
  }
cfence.Say("Total value is %d $", totalvalue);
}
 }


  Error: totalvalue=inventory[itemid].GetProperty("moneyvalue");


When this script is correct all i need to do is add to score when a new item is added to inventory..  when you reach the end a condition will check how many points you have and display appropriate text display.

I have created variables called 'moneyvalue and 'totalvalue' and the inventory window name is invCustomInv if that's any use.

cheers for any further help with this

barefoot




I May Not Be Perfect but I Have A Big Heart ..

barefoot

#11
Hi

Update

after creating a variable called Total (Total, int, value 0) I use this to add to it ($50):

 Total = (Total + 50);
 Display("You have $50");
 Display("Total: %d", Total);

I do this for every inventory collected.. so it totals up as each inventory item is found.

Is there a way to Display $50 rather than just 50?

I just need help with the <>= .. any help would be appreciated.

Plus if score=this or that then display this..

Am I on the right track?

I shall persevere

cheers for any assistance on this matter

barefoot








I May Not Be Perfect but I Have A Big Heart ..

Gilbert

1.
QuoteTotal = (Total + 50);
This is not important, but you don't actually need the parentheses here. It is not a function. You only need them when you have to clearly specify the order of the arithmetic operations. So:
Total = Total + 50;
(or even lazier: Total += 50;)
2.
QuoteIs there a way to Display $50 rather than just 50?
Yes:
Display("Total: $%d", Total);
3.
QuoteI just need help with the <>= .. any help would be appreciated.
I never have time to really read this thread, but did you mean the comparison operators ==, <>, >, <, >= and <= here?
You just use them when you are doing comparisons, like:
Code: ags

if (var > 100) {
  blah bla
} else {
  blah bla bla
}


barefoot

Many many thanks Gilbet

Done the $ done in display.. Works..

I will have to do a full research of var and operators..

I'm assuming my solution find is almost there?

cheers

barefoot

I May Not Be Perfect but I Have A Big Heart ..

Khris

Quote from: barefoot on Mon 24/01/2011 06:31:25
But not this bit:

Code: ags

else {
 int i; totalvalue, itemid;

  // snip


Error:
Failed to save room room1.crm; details below
room1.asc(152): Error (line 152): PE04: parse error at 'totalvalue'

There's a typo in that line; just replace the semi-colon with a comma.

barefoot

#15
Cheers Khris

I will amend and  recopy the code and stick it in notepad... thanks

I have decided to have a points ($) system. When an inv item is collected it adds an amount to the total etc..  It seems to work ok.

So far so good.

barefoot
I May Not Be Perfect but I Have A Big Heart ..

Khris

No offense, but I really have a hard time getting what the hell the problem seems to be.

I provided you with code; all you have to do is stick a complete list of sell-able inventory items in there and there you go.
The fence will mention all the stuff he's interested in buying using a nice, comma-separated list with "and" at the end, and tells you about the money, exactly like you wanted it to work.
Since the player can't decline the offer anyway, all you have to do is let the player say "thanks for the money" or something, add sum (the variable containing the total amount) to the variable holding the player's money and send them on their way. ( money += sum; )

I asked you whether you needed in addition e.g. the total value of items currently carried by the player or something like that, but no, you didn't. Even if you did, all you have to do is add a value property to inventory items and change the code slightly to use that to calculate the sum, in case you want to tell the player about the items' value elsewhere in the game.

This is one of the most trivial coding problems ever, and after multiple people try to help you, you decide to do it another way. I don't get it.
I'm aware that you are a beginner, but you'll have to face coding at some point if you want to do a decent game.

barefoot

Hi Khris

None taken...

Things can get a little daunting and my scripting inexperience can make things confusing at times.

Unfortunately i lost all my written codes so i have to try and remember them or search/ask here.

It's like you know what you want but don't know how to achieve or implement it..

I really appreciate your help/advice.. maybe i did not choose the best method first time...

If i had known how to add a score/points system then there would not have been a problem.. But i've learnt and implemented a score/point system that does what i was aiming for but never knew how to do it..

In the end I achieved what i was looking for and i will be more specific next time maybe after a long think about it first.

Cheers Khris

Les






I May Not Be Perfect but I Have A Big Heart ..

Dualnames

Barefoot. I'm sure Khris has given you a working code and mine works as well,
Quote
There may be parse errors or small continuity stuff that I missed. And you need to create a property called moneyvalue with default value 0 and the property being a number. All you need to do is just clarify each item's value and you're set.

You seem to have missed reading this, if you don't understand the code I gave you, why not ask me? This way, you'll learn stuff. (I'm not acting cocky btw)

Point is that there was a simple parse error that I kind of warned about. Now it's 3 people trying to solve your problem with probably 3 different approaches.

Code: ags
 totalvalue=+inventory[itemid].GetProperty("moneyvalue");


If this line is giving the error, change it to:
Code: ags
 totalvalue+=inventory[itemid].GetProperty("moneyvalue");


I always mix those and never remember it by heart.

This should give no errors.
Code: ags

cFence.Say("Let's see what you got !");
 if (inventorywindow.ItemCount==0) {
     cFence.Say("You got nothing.");
 }
 
else {
 int i, totalvalue, itemid;
  while (i!= inventorywindow.ItemCount) {
    itemid=inventorywindow.ItemAtIndex[i].ID;
    totalvalue=totalvalue + inventory[itemid].GetProperty("moneyvalue");
    i++;
  }
cFence.Say("Total value is %d $", totalvalue);
}
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

barefoot

Hi Dualnames

I agree with you but its like I've already said... but at least i have learnt a few options... it just got a little confusing... but i will certainly copy your code above and keep it along with Khri's for reference....getting to a final solution is very relieving as you yourself know and i did not intend to shake the bees nest.

thanks again to those that contributed

barefoot

I May Not Be Perfect but I Have A Big Heart ..

SMF spam blocked by CleanTalk