GetWord ?
by Dreamer · in Torque Game Engine · 04/26/2005 (10:04 am) · 8 replies
Does how does getWord view commas? Are they viewed as possible seperators or as part of the word? I'm rewriting a section of my Tradeskills code and wanted to use a vector to save storage space and retrieval time in the database, so let me show you a for instance...
%reagents = "Salt,Water,Taffy";
Now if I use getWord to cycle through %reagents would it view those as 3 seperate words or would it view that as a single word with commas?
%reagents = "Salt,Water,Taffy";
Now if I use getWord to cycle through %reagents would it view those as 3 seperate words or would it view that as a single word with commas?
#2
04/26/2005 (10:11 am)
Actually I'm asking HOW the getWord function would view that statement either as a single word or as 3 seperate words, I'm looking to pull the value which is already stored like that in the DB, and do the minimum possible to get the result I need for my recipies function to work correctly again.
#3
04/26/2005 (10:16 am)
It would view it as one word. What do you mean they are stored in the DB with commas, they shouldn't be. Each value should be on its own. You might want to parse the info from commas to spaces before it is recieved by Torque.
#4
- Brett
04/26/2005 (10:22 am)
GetWords separates on spaces, getFields on tabs, and getRecords I think does commas.- Brett
#5
04/26/2005 (10:29 am)
Ahh ok, that helps alot, as for storing with commas, thus far I have seen no issues, but then again my DB code automatically escapes on insert and strips on retrieve, so that could be why I'm not seeing it.
#6
04/30/2005 (12:22 pm)
So you're using csv database. Try using TAB seperated, that would be poratable. So your string would look like..%reagents = "Salt TAB Water TAB Taffy";
#7
04/30/2005 (3:01 pm)
If you've got other code that uses the commas, however, you can always strip them out using something like:// Declare the string to strip. %stripMe = "Salt,Water,Taffy"; // Replace all the commas in the string with spaces. %stripMe = strReplace(%stripMe, ",", " "); // Get the second word from the string. %word = getWord(%stripMe, 1);
#8
@Daniel, I wound up doing something similar to get everything to work properly, instead of using commas for each word I just added and stripped underscores as needed.
The system functions like this FYI
Insert into the DB a recipie name, the final product is comprised of ingredients listed in the names.
The code looks at recipies whose final produced item include the ingredient word, lets say salt.
It would find "Salt_Water_Taffy 1 1 1" it strips the underscores and comes up with a vector of 3 ingredients Salt Water and Taffy
Salt and Water are both primary ingredients, so it then looks for Taffy
Taffy is comprised of "Sugar_Water_Salt 1 1 1"
Stripped this means we need Sugar Water and Salt
In his inventory we do a check and find that our player has 3 sugars, 2 Waters and 4 Salts
Take from player 1 sugar 1 water 1 salt and give back 1 Taffy
Take from player 1 salt 1 water 1 taffy and give back 1 Salt_Water_Taffy
Pretty cool huh? With this we can create some really interesting recipies just by having the players attempt to combine/cook whatever is in there inventory and see what is produced. I also intend to add stat and skill boosts to primary ingredients, and have new items inherit them.
05/02/2005 (9:24 am)
@Ralph Thanks for the help, actually I'm using a SQLite DB mod as written by John Vanderbeck and modded by me to work in linux.@Daniel, I wound up doing something similar to get everything to work properly, instead of using commas for each word I just added and stripped underscores as needed.
The system functions like this FYI
Insert into the DB a recipie name, the final product is comprised of ingredients listed in the names.
The code looks at recipies whose final produced item include the ingredient word, lets say salt.
It would find "Salt_Water_Taffy 1 1 1" it strips the underscores and comes up with a vector of 3 ingredients Salt Water and Taffy
Salt and Water are both primary ingredients, so it then looks for Taffy
Taffy is comprised of "Sugar_Water_Salt 1 1 1"
Stripped this means we need Sugar Water and Salt
In his inventory we do a check and find that our player has 3 sugars, 2 Waters and 4 Salts
Take from player 1 sugar 1 water 1 salt and give back 1 Taffy
Take from player 1 salt 1 water 1 taffy and give back 1 Salt_Water_Taffy
Pretty cool huh? With this we can create some really interesting recipies just by having the players attempt to combine/cook whatever is in there inventory and see what is produced. I also intend to add stat and skill boosts to primary ingredients, and have new items inherit them.
Associate Anthony Rosenbaum
%reagents = "Salt Water Taffy";