storing text in vars?

Forum Archive - from http://theuniversal.net
Locked
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

storing text in vars?

Post by zaroba »

Thought storing text in vars was possible?

Event( "&command" "test" )
{
$gPlayerVar33=sysGetItemName("10")
*say $gPlayerVar33
}

just reports '0'

also tried:
$gPlayerVar33=sysGetItemName(10)
$gPlayerVar33=%player%
$gPlayerVar33=text
$gPlayerVar33="text"
$gPlayerVar33=("text")
$gPlayerVar33=(text)
$gPlayerVar32=10 with $gPlayerVar33=sysGetItemName($gPlayerVar32)
$gPlayerVar32=10 with $gPlayerVar33=sysGetItemName("$gPlayerVar32")
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

Storing strings in local or module vars is possible, but not in the $gPlayerVar, $gPlayerTimeVar, $gServerVar etc (These are all specifically integers)

Code: Select all

$localVar = sysGetItemName(10)
*say $localVar
would work. Have you got a specific use case where you need to store strings in systems vars?
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

Since all of zorics buildings are scripted, I was thinking of having the script set playervars to the itemnames when first accessing the buildings. This would allow the building display script to use these vars in place of any instance where an item name would be shown. The buildings make use of up to 15 different items which are stored via setting bvars (not physical items) so currently the script has to be unique to each building.

If the script would be using playervars set via the accessbuilding event, the script could be cut down (I'm estimating) 30-50% due to not needing to have everything replicated for each building to cater to the different items in each building.

The script for building owners is around 75 pages long. 30 buildings with 75 page scripts = 2,250 pages worth of script. The more that can be removed from each one, the smaller the script. With the above method, I could very easily consolidate the first 25 pages from each script (building Inventory Management) and this alone would save 750 pages worth of script. Other stuff would need a bit more work to condense down a bit.

The script for customer access (item buying/selling and jobs) isn't made yet, but it wont be far different form the building Inventory Management thing above. Having one 50 page script would be better then 30 different 50 page scripts (1500 pages) due to needing to use different item names.

Plus it'd be easier then manually putting the names in all the different scripts. lol




Although, if the local vars can retain their values threw OSD buttons and customevent clauses, they would work too.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

mmm.. yes to the last bit.. Thats how most of my stuff works.

Don't see any reason why any of this implies the need to store text. If you just store the item numbers you can get the item name out with sysGetItemName( $itemNum )

Not quite sure why you're considering playervars in this at all. Sounds complicated and dangerous to me :]
The buildings make use of up to 15 different items which are stored via setting bvars (not physical items) so currently the script has to be unique to each building
mmm.. Any particular reason you're using bvars for this rather than the standard building stocks? (i.e. Making use of *setbuyprice, *setsellprice, sysAmountInStocks(..), *removefromstocks etc etc)

Anyway, this sounds like something im doing with the next world (and to a certain extent is how civ operated).. For each unique building type i've added a wee admin function that adds in and sets up a unique set of items and their prices. Once they're set, all the different buildings use the same set of functions to display the OSD and handle the transactions.
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

The main reason it's being done via building vars is an attempt to make a world that uses the script as much as possible and to provide more features and realism then the basic bdat does.

All building production is going to be done via script to allow players to choose what buildings make and how much to make. Players can upgrade their buildings by adding additional production slots to produce more things at a time (different or the same) and if not provided with proper maintenance these production slots will 'break down' and need repairs before they can be used again. Corporations will also likely have the ability to commit espionage on other corporation buildings to stop production or break the production lines.


So far, it's just going to be player inventory and player houses that deal with physical items. Was even thinking of scripting the hunger/thirst stuff and at-home stuff, complete with the ability to cook via your oven.
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

nevermind, local vars wont store their value threw custom event changes.


testing with this thingy to make entering quantities easier.
the $quantity var gets reset with each custom event change, as does the $price var

Code: Select all

Event( "&command" "test" )
	{
	*say price set to 5
	$price=5
	CustomEvent("numpad")
	}

Event("custom", "numpad")
	{
	*say quantity $quantity  - price $price
	osdcreate(OSDBUILDING,"num","Employee Menu")
	osdaddat(BIGTEXT, 25, 50, , , "", "Quantity $quantity")
	if ($cost>0)
		{
		osdaddat(BIGTEXT, 25, 200, , , "", "Total Cost $cost")
		}
	if ($tax>0)
		{
		osdaddat(BIGTEXT, 25, 300, , , "", "(not including tax)")
		}
	osdaddat(BIGTEXT, 50, 65, , , "", "Type in the amount you desire")
	osdaddat(OSDBUTTON, 100, 100, 50, 20, "num7", "7")
	osdaddat(OSDBUTTON, 150, 100, 50, 20, "num8", "8")
	osdaddat(OSDBUTTON, 200, 100, 50, 20, "num9", "9")
	osdaddat(OSDBUTTON, 100, 150, 50, 20, "num4", "4")
	osdaddat(OSDBUTTON, 150, 150, 50, 20, "num5", "5")
	osdaddat(OSDBUTTON, 200, 150, 50, 20, "num6", "6")
	osdaddat(OSDBUTTON, 100, 200, 50, 20, "num1", "1")
	osdaddat(OSDBUTTON, 150, 200, 50, 20, "num2", "2")
	osdaddat(OSDBUTTON, 200, 200, 50, 20, "num3", "3")
	osdaddat(OSDBUTTON, 100, 250, 75, 20, "num0", "0")
	osdaddat(OSDBUTTON, 175, 250, 75, 20, "num00", "00")
	osdaddat(OSDBUTTON, 300, 100, 125, 50, "numreset", "Reset quantity")
	osdaddat(OSDBUTTON, 300, 150, 125, 50, "numback", "Backspace")
	osdaddat(OSDBUTTON, 300, 250, 125, 50, "numok", "Confirm")
	osdaddat(OSDBUTTON, 300, 300, 130, 20, "exit", "Cancel")
	osdactivate()
	}


Event( "OSDSelect", "num:num1" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*10
		$quantity=$quantity+1
		}
	if ($quantity=0)
		{
		$quantity=1
		}
	$cost=$quantity*$price
	*say $quantity
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:num2" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*10
		$quantity=$quantity+2
		}
	if ($quantity=0)
		{
		$quantity=2
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:num3" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*10
		$quantity=$quantity+3
		}
	if ($quantity=0)
		{
		$quantity=3
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:num4" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*10
		$quantity=$quantity+4
		}
	if ($quantity=0)
		{
		$quantity=4
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:num5" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*10
		$quantity=$quantity+5
		}
	if ($quantity=0)
		{
		$quantity=5
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:num6" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*10
		$quantity=$quantity+6
		}
	if ($quantity=0)
		{
		$quantity=6
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:num7" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*10
		$quantity=$quantity+7
		}
	if ($quantity=0)
		{
		$quantity=7
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:num8" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*10
		$quantity=$quantity+8
		}
	if ($quantity=0)
		{
		$quantity=8
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:num9" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*10
		$quantity=$quantity+9
		}
	if ($quantity=0)
		{
		$quantity=9
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:num0" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*10
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:num00" )
	{
	if ($quantity>0)
		{
		$quantity=$quantity*100
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:numreset" )
	{
	$quantity=0
	$cost=0
	CustomEvent("numpad")
	}

Event( "OSDSelect", "num:numback" )
	{
	if ($quantity<10)
		{
		$quantity=0
		}
	if ($quantity>9)
		{
		$quantity=$quantity/10
		}
	$cost=$quantity*$price
	CustomEvent("numpad")
	}
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

Figured out a workaround for the original issue that may prove more useful then the original plan.

-buildings will store item numbers in vars (besides just the qty and buy/sell price)
-there will be a server var set and buildings must have a var that matches this var
-if the building's var does not match the server var, then a custom event is run to set the building vars to the specific item numbers as needed.

A new building wont have any of the vars set, but when the owner accesses it, the script will run and update the buildings vars. This system will also allow very easy adding and removing items from buildings if needed. The building inventory screen will convert the building var values into item names to be displayed when buying/selling/adding/removing stocks from buildings.




Also fixed and completed the number pad script (the above piece was just the initial 'proof of concept' i always do) and combined with a few 'temp' playervars the single script can be used to set values anywhere number manipulation is needed. Setting buy/sell prices, specifying amounts to add or remove from stock, even setting the building sale price and adding/removing building investment. Complete with checks for everything so there are no exploitable loopholes.
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

mmm :)
so yeh, $quantity in your script above will always be 0 when it enters the function or event. See details on local, module and global variables in
http://theuniversal.net/worldmanual/dok ... sic_syntax

(You could make it a module variable and have it retain its value between functions/events, but thats probably not what you want - it'll go horribly wrong when two people use your script at the same time - same is somewhat true if you're using building vars instead).

Its a funky bit of script, but methinks what you really is for me to extend the OSD value control so the user can input values there directly..
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

ideally yea, players being able to type in the quantity would be great, for more then just this script as well. Failing that though, this workaround should work nd be problem free via using playervars to store the important numbers.

If you'd like to see it, I got no problems with posting it.
Although given your programming expertise, it probably wouldn't look like anything special to you, plus you could likely do the same thing in a far easier way :p
Locked