Stores and Shops

steve the gaming guy
25 Aug 2005, 15:29
I looked through a couple threads on here concerning shops and stores but it didn't help me exactly. I want the player to go to a room called "store" and while he is in there, if he types "buy #@object#", then the store procedure is called as below.
I tried a couple angles here. First, I tried using the property of the objects. I made the table with property cost=100. I can't really do much with it. So then I made it "if #@object# = table" which seems to work for me. HOWEVER, I added an else msg to not allow him to purchase if the amount of money is less than 100. What happens instead is that even if the player has 500, it still produces the message that he doesn't have enough.
Am I writing this wrong? Is there a better way to create a store?

define procedure <store>
if ( #@object# = table ) then {
if ( money > 100 ) then {
dec <money; 100>
clone <table; new table; house1>
give <new table>
}
else msg <You do not have enough money to purchase the #@object#.>
}
end define

Arbutus
25 Aug 2005, 16:45
if ( %money% > 100 ) then {

paul_one
25 Aug 2005, 23:22
Using object properties:
command <buy #@object#> { ' put's object's REAL name into #object#
if ( #(object):cost# < %money% ) then {
give <#object#>
set numeric <money; %money% - #(object):cost# >
}
else msg <Not enough money>
}

If the above doesn't work, try replacing the if with:
set numeric <cost; $objectproperty(#object#;cost)$>
if ( %cost% < %money% ) then {


I was making a shop IIRC, and it's what I used... kinda.

Oh, if you wish to clone an object, make sure you don't have a specific name to make it, use a numeric variable to *count* it (ie. clone <object; object%number%> )... You can also clone it directly into the inventory (clone<obj;obj%num%;inventory> IIRC).

I may write a little addition to my general ASL library... I will find it useful too.
A clone function, that returns the name of the clone it created - but also creates an array of names, so if you keep on cloning an object - then want to (say) remove ALL of these objects from the player - all you do is cycle through the array... Nice!
... I will take lots of time off work tomorrow, worked an extra 2 hours and should actually have been off this week, so my boss owes me ;) .

steve the gaming guy
26 Aug 2005, 18:20
That's cool. I will have to try that one too.
The reason why I tried to use cloning was because when I have the player enter the store, they see the objects that are able to be purchased. When they buy a table, for instance, the table goes into their inventory and one stays in the store.
I'm sure there's a better way to do that though.

paul_one
28 Aug 2005, 02:13
I added cloning to my general library:
File

Unfortunately I can't *really* test it - but the link *should* work.

I've updated the txt file and the library itself.
Test it out, and please report any errors.
You can post them, PM me or email me.

Any other suggestions are welcome.

Thank you.

[EDIT]
Uploaded zip file to online server, changed link accordingly.