|
Lorrdian Newbie
Joined: 13 Dec 2011 Posts: 4
|
Posted: Tue Dec 13, 2011 8:39 pm
DB putting fields on separate records |
I just started a database last night and it keeps putting the fields on separate records, and I can't understand why
Here is how it is set up, essentially
var-@shipid=Originally set to 1, this is the number that should be used to specify record number
@Shipname
@Ownername
@Dockname
I have 3 triggers
Ship information~:%1
#var @shipid + 1
#var @Shipname %1
#dbput @shipid Ship_Name(field) @Shipname
Owner~:%1
#var @Ownername %1
#dbput @shipid Owner(field) @Ownername
Dock~:%1
#var @Dockname %1
#dbput @shipid Dock(field) @Dockname
What I get is
Record Ship_Name Owner Dock
1 Titanic
2 Nemo
3 Florida
Under their correct fields (not letting me insert spaces for some reason)
Instead of
1 Titanic Nemo Florida
Essentially what I'm trying to do is store all of the information I look up so I can easily retrieve it and use it for other things, such as a traffic monitor
Can anyone tell me what I'm doing wrong? |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Tue Dec 13, 2011 9:37 pm |
Are those the actual trigger patterns and trigger values from your scripts? If so...
Problem 1) Do not use %1, %2, etc. within a trigger pattern.
Problem 2) "#VAR @shipid + 1" is wrong. It should be: "#VAR shipid (@shipid + 1)"
Problem 3) Similarly, "VAR @Shipname %1" is wrong. Do not use @ when specifing the variable name for #VAR: "#VAR shipid %1"
Problem 4) Why do you have (field) in your scripts? If you don't, and that is just an explanatory text for us, ignore this.
I don't think any of these things are causing your ultimate problem, but you need to fix them first before we can tell anything else.
To post the actual code of your scripts, go to the Package Editor. Click on the script to open it. At the botton of the script window, click the XML tab to display the XML code. Select the entire code, and CTRL-C to copy it to the buffer. Come here to your reply message. In your message, type: [code]. Then paste your code. Then type [\code]. |
|
|
|
Lorrdian Newbie
Joined: 13 Dec 2011 Posts: 4
|
Posted: Tue Dec 13, 2011 9:42 pm |
1. What should I use? I'm trying to capture everything after the trigger pattern, and input that into the database field
2. I'll fix that
3.I was doing this from memory so I'm sorry. It is #var shipid %1
4. Field was just explanatory text.
I'll try and post the actual script When I get home.
It's a bunch of separate triggers, but all in one class. Will I be able to still export it? |
|
|
|
Lorrdian Newbie
Joined: 13 Dec 2011 Posts: 4
|
Posted: Wed Dec 14, 2011 12:27 am |
Code: |
<class name="ShipDB" id="185">
<var name="shipid" id="181">1</var>
<var name="shipname" id="182"> '</var>
<var name="ownername" id="183"> </var>
<var name="dockname" id="184"></var>
<trigger priority="1871" id="186">
<pattern>^Ship Information~:%1</pattern>
<value>#var shipid (@shipid+1)
#var shipname %1
#DBPUT @shipid Ship_Name @shipname</value>
</trigger>
<trigger priority="1870" id="187">
<pattern>^Ship Owner~:%1</pattern>
<value>
#var ownername %1
#dbput @shipid Owner @ownername</value>
</trigger>
<trigger priority="1880" id="188">
<pattern>Dock~:%1</pattern>
<value>#var dockname %1
#dbput @shipid Dock @dockname</value>
</trigger>
<var name="planetname" id="189"></var>
<trigger priority="1900" id="190">
<pattern>Planet~:%1</pattern>
<value>#var planetname %1
#dbput @shipid Planet_Name @planetname
#dbsave</value>
</trigger>
</class>
|
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Dec 14, 2011 3:23 am |
1) In the patterns, replace %1 with (*). Include the parentheses. The parentheses mean "capture whatever matches this", and the asterisk means "match anything". If you wanted to be more specific, you could use other patterns, like (%w), which would capture exactly one word. Within the script, you can then refer to whatever was captured by the first set of parentheses with %1, the second set of parentheses by %2, etc.
My first guess as to the big problem is that perhaps #DBPUT does not allow the record number to be a variable. It has been a long time since I played with #DBPUT, so I'm not sure. |
|
|
|
Lorrdian Newbie
Joined: 13 Dec 2011 Posts: 4
|
Posted: Wed Dec 14, 2011 1:48 pm |
Here is the new code..I got it working. The only problem now is that if I scan a ship that I have scanned before, it will create a duplicate entry instead of updating the info
Code: |
<class name="ShipDB" id="185">
<var name="shipid" id="181">61</var>
<var name="shipname" id="182"></var>
<var name="ownername" id="183"></var>
<var name="dockname" id="184"></var>
<var name="planetname" id="189"></var>
<trigger priority="1930" id="193">
<pattern>Ship Information: &Ship.Ship_Name</pattern>
</trigger>
<trigger priority="1940" id="194">
<pattern>Ship Owner: &Ship.Owner</pattern>
</trigger>
<trigger priority="1950" id="195">
<pattern>Dock: &Ship.Dock</pattern>
</trigger>
<trigger priority="1960" id="196">
<pattern>Planet: &Ship.Planet</pattern>
</trigger>
<trigger priority="1871" id="198">
<pattern>^Ship Information~:(*)</pattern>
<value>#var shipid (@shipid+1)
#var shipname %1
#DBPUT @shipid Ship_Name @shipname
//say @shipname</value>
</trigger>
<trigger priority="1870" id="199">
<pattern>^Ship Owner~:(*)</pattern>
<value>#var ownername %1
#dbput @shipid Owner @ownername
//Say Owned by @ownername</value>
</trigger>
<trigger priority="1880" id="200">
<pattern>Dock~:(*)</pattern>
<value>#var dockname %1
#dbput @shipid Dock @dockname
//say Last docked at @dockname</value>
</trigger>
<trigger priority="1900" id="201">
<pattern>Planet~:(*)</pattern>
<value>#var planetname %1
#dbput @shipid Planet_Name @planetname
#dbsave
//say On Planet @planetname</value>
</trigger>
<var name="currplan" id="202"></var>
</class>
|
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Dec 14, 2011 8:35 pm |
Hm. I suggest a second variable, perhaps named @curshipid. In your #DBPUT commands, use @curshipid instead of @shipid. In the Ship_Name trigger, have it query the database first to see if the ship is already in it. If it is, set @curshipid to that value. If it is not in the database, increment @shipid and set @curshipid equal to the new value of @shipid.
|
|
|
|
|
|