HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Save/Load bug.

03-29-2008, 07:37 PM#1
n[o]oblet
I had taken a break from Wc3 for a while, and now I'm back and trying to re-learn everything.. So I was following a tutorial off of this site for Save/Loading. When I test it, it doesn't load..
Here's my triggers..
Trigger:
Save
Collapse Events
Player - Player 1 (Red) types a chat message containing -save as An exact match
Conditions
Collapse Actions
-------- Setting Stats --------
Set PasswordParts[1] = (String((Hero experience of Hero[(Player number of (Triggering player))])))
Set PasswordParts[2] = (String(((Triggering player) Current gold)))
Set PasswordParts[3] = (String(((Triggering player) Current lumber)))
-------- Save Hero Type --------
If ((Unit-type of Hero[(Player number of (Triggering player))]) Equal to Paladin) then do (Set PasswordParts[4] = 1) else do (Do nothing)
If ((Unit-type of Hero[(Player number of (Triggering player))]) Equal to Archmage) then do (Set PasswordParts[4] = 2) else do (Do nothing)
If ((Unit-type of Hero[(Player number of (Triggering player))]) Equal to Mountain King) then do (Set PasswordParts[4] = 3) else do (Do nothing)
-------- Combine to Password --------
Collapse For each (Integer A) from 1 to 4, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Integer A) Equal to 4
Collapse Then - Actions
Set Password_before_encrypt_1 = (Password_before_encrypt_1 + (PasswordParts[(Integer A)] + <Empty String>))
Collapse Else - Actions
Set Password_before_encrypt_1 = (Password_before_encrypt_1 + (PasswordParts[(Integer A)] + -))
-------- Reverse the String --------
Collapse For each (Integer A) from 0 to ((Length of Password_before_encrypt_1) - 1), do (Actions)
Collapse Loop - Actions
Set Password_before_encrypt_2 = (Password_before_encrypt_2 + (Substring(Password_before_encrypt_1, ((Length of Password_before_encrypt_1) - (Integer A)), ((Length of Password_before_encrypt_1) - (Integer A)))))
-------- Encrypt --------
Collapse For each (Integer A) from 1 to (Length of Password_before_encrypt_2), do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Substring(Password_before_encrypt_2, (Integer A), (Integer A))) Not equal to -
Collapse Then - Actions
Set final_password = (final_password + (String((9 - (Integer((Substring(Password_before_encrypt_2, (Integer A), (Integer A)))))))))
Collapse Else - Actions
Set final_password = (final_password + -)
-------- Display Password --------
Game - Display to (Player group((Triggering player))) for 60.00 seconds the text: (Your password is: + (|cffff0303 + final_password))
Game - Display to (Player group((Triggering player))) for 45.00 seconds the text: You'll need to save...
Trigger:
Load
Collapse Events
Player - Player 1 (Red) types a chat message containing -load as A substring
Conditions
Collapse Actions
Set final_password = <Empty String>
Set loadstring = (Substring((Entered chat string), 6, (Length of (Entered chat string))))
Collapse For each (Integer A) from 0 to ((Length of loadstring) - 1), do (Actions)
Collapse Loop - Actions
Set Unencrypt2 = (Unencrypt2 + (Substring(loadstring, ((Length of loadstring) - (Integer A)), (((Length of loadstring) - (Integer A)) + 0))))
Collapse For each (Integer A) from 1 to ((Length of Unencrypt2) - 1), do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Substring(Unencrypt2, (Integer A), (Integer A))) Not equal to -
Collapse Then - Actions
Set final_password = (final_password + (String((9 - (Integer((Substring(Unencrypt2, (Integer A), (Integer A)))))))))
Collapse Else - Actions
Set final_password = (final_password + -)
Collapse For each (Integer A) from 1 to (Length of Unencrypt2), do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse Or - Any (Conditions) are true
Collapse Conditions
Collapse And - All (Conditions) are true
Collapse Conditions
(Substring(final_password, (Integer A), (Integer A))) Equal to -
(Substring(final_password, ((Integer A) + 1), ((Integer A) + 1))) Not equal to -
Collapse Then - Actions
Set current_pswd_part = (current_pswd_part + 1)
Set PasswordParts[current_pswd_part] = (Substring(final_password, oldstop, (Integer A)))
Set oldstop = (Integer A)
Else - Actions
Collapse For each (Integer A) from 1 to 6, do (Actions)
Collapse Loop - Actions
Collapse For each (Integer B) from 1 to (Length of PasswordParts[(Integer A)]), do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Substring(PasswordParts[(Integer B)], (Integer B), (Integer B))) Equal to -
Then - Actions
Collapse Else - Actions
Set temporary_password_string = (temporary_password_string + (Substring(PasswordParts[(Integer A)], (Integer B), (Integer B))))
Set PasswordParts[(Integer B)] = temporary_password_string
Set temporary_password_string = <Empty String>
-------- Create! --------
If (PasswordParts[4] Equal to 1) then do (Unit - Create 1 Paladin for (Triggering player) at ((Triggering player) start location) facing (Center of (Entire map))) else do (Do nothing)
If (PasswordParts[4] Equal to 2) then do (Unit - Create 1 Archmage for (Triggering player) at ((Triggering player) start location) facing (Center of (Entire map))) else do (Do nothing)
If (PasswordParts[4] Equal to 3) then do (Unit - Create 1 Mountain King for (Triggering player) at ((Triggering player) start location) facing (Center of (Entire map))) else do (Do nothing)
Hero - Set (Last created unit) experience to (Integer(PasswordParts[1])), Hide level-up graphics
Player - Set (Triggering player) Current gold to (Integer(PasswordParts[2]))
Player - Set (Triggering player) Current lumber to (Integer(PasswordParts[3]))

I think it may have something to do with me changing 6 values for PasswordParts to 4. But I can't seem to figure out where the bug is...

Thx in advanced..
~NoobleT
03-29-2008, 11:17 PM#2
Zandose
I'm just going to put comments in (//text).

Trigger:
Save
Collapse Events
Player - Player 1 (Red) types a chat message containing -save as An exact match
Conditions
Collapse Actions
-------- Setting Stats --------
Set PasswordParts[1] = (String((Hero experience of Hero[(Player number of (Triggering player))])))
Set PasswordParts[2] = (String(((Triggering player) Current gold)))
Set PasswordParts[3] = (String(((Triggering player) Current lumber)))
-------- Save Hero Type --------
If ((Unit-type of Hero[(Player number of (Triggering player))]) Equal to Paladin) then do (Set PasswordParts[4] = 1) else do (Do nothing)
If ((Unit-type of Hero[(Player number of (Triggering player))]) Equal to Archmage) then do (Set PasswordParts[4] = 2) else do (Do nothing)
If ((Unit-type of Hero[(Player number of (Triggering player))]) Equal to Mountain King) then do (Set PasswordParts[4] = 3) else do (Do nothing)
-------- Combine to Password --------
//This is messed up. You going to end up with something like this "----9827".
//Move "Set Password_before_encrypt_1 = (Password_before_encrypt_1 + (PasswordParts[(Integer A)] + <Empty String>))" to before the if statement.
//Delete the if statement and create a new one.
//Use this instead:
Collapse //-----------------
Collapse For each (Integer A) from 1 to 4, do (Actions)
Loop - Actions
Collapse Set Password_before_encrypt_1 = (Password_before_encrypt_1 + PasswordParts[(Integer A)])
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Integer A) Equal to 4
Then - Actions
Collapse Else - Actions
Set Password_before_encrypt_1 = (Password_before_encrypt_1 + -)
Collapse //-----------------
Collapse For each (Integer A) from 1 to 4, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Integer A) Equal to 4
Collapse Then - Actions
Set Password_before_encrypt_1 = (Password_before_encrypt_1 + (PasswordParts[(Integer A)] + <Empty String>))
Collapse Else - Actions
Set Password_before_encrypt_1 = (Password_before_encrypt_1 + (PasswordParts[(Integer A)] + -))
-------- Reverse the String --------
Collapse For each (Integer A) from 0 to ((Length of Password_before_encrypt_1) - 1), do (Actions)
Collapse Loop - Actions
Set Password_before_encrypt_2 = (Password_before_encrypt_2 + (Substring(Password_before_encrypt_1, ((Length of Password_before_encrypt_1) - (Integer A)), ((Length of Password_before_encrypt_1) - (Integer A)))))
-------- Encrypt --------
Collapse For each (Integer A) from 1 to (Length of Password_before_encrypt_2), do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Substring(Password_before_encrypt_2, (Integer A), (Integer A))) Not equal to -
Collapse Then - Actions
Set final_password = (final_password + (String((9 - (Integer((Substring(Password_before_encrypt_2, (Integer A), (Integer A)))))))))
Collapse Else - Actions
Set final_password = (final_password + -)
-------- Display Password --------
Game - Display to (Player group((Triggering player))) for 60.00 seconds the text: (Your password is: + (|cffff0303 + final_password))
Game - Display to (Player group((Triggering player))) for 45.00 seconds the text: You'll need to save...

Trigger:
Collapse Load
Collapse Events
Player - Player 1 (Red) types a chat message containing -load as A substring
Conditions
Collapse Actions
Set final_password = <Empty String>
Collapse Set Unencrypt2 = <Empty String>
Set loadstring = (Substring((Entered chat string), 6, (Length of (Entered chat string))))
Collapse //I think you need to swich this loop and the next one. Your reversing the string before you unencrypt it, when you should be doing the opposite.
Collapse For each (Integer A) from 0 to ((Length of loadstring) - 1), do (Actions)
Collapse Loop - Actions
Set Unencrypt2 = (Unencrypt2 + (Substring(loadstring, ((Length of loadstring) - (Integer A)), (((Length of loadstring) - (Integer A)) + 0))))
Collapse For each (Integer A) from 1 to ((Length of Unencrypt2) - 1), do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Substring(Unencrypt2, (Integer A), (Integer A))) Not equal to -
Collapse Then - Actions
Set final_password = (final_password + (String((9 - (Integer((Substring(Unencrypt2, (Integer A), (Integer A)))))))))
Collapse Else - Actions
Set final_password = (final_password + -)
Collapse For each (Integer A) from 1 to (Length of Unencrypt2), do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
//Get rid of the "Or" and "And" conditions, keeping the "(Substring(final_password, (Integer A), (Integer A))) Equal to -".
Collapse //Otherwise, this is always going to return false, since your code cannot have a "-" in two places at the same time.
Collapse Or - Any (Conditions) are true
Collapse Conditions
Collapse And - All (Conditions) are true
Collapse Conditions
(Substring(final_password, (Integer A), (Integer A))) Equal to -
(Substring(final_password, ((Integer A) + 1), ((Integer A) + 1))) Not equal to -
Then - Actions
//Change the "(Integer A)" in "Set PasswordParts[current_pswd_part]" to "((Integer A) - 1)".
//Change the "(Integer A)" in "Set oldstop = (Integer A)" to "((Integer A) + 1)".
Collapse //This should remove any "-" from the codes.
Set current_pswd_part = (current_pswd_part + 1)
Set PasswordParts[current_pswd_part] = (Substring(final_password, oldstop, (Integer A)))
Set oldstop = (Integer A)
Else - Actions
//You can change this loop from 6 to 4.
//Get rid of this whole loop, extect for the "-------- Create! --------" part. It has it's own comment on what to do with it.
Collapse For each (Integer A) from 1 to 6, do (Actions)
Collapse Loop - Actions
Collapse For each (Integer B) from 1 to (Length of PasswordParts[(Integer A)]), do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
//Remove this, since any "-" have been removed.
(Substring(PasswordParts[(Integer B)], (Integer B), (Integer B))) Equal to -
Then - Actions
Else - Actions
Set temporary_password_string = (temporary_password_string + (Substring(PasswordParts[(Integer A)], (Integer B), (Integer B))))
Set PasswordParts[(Integer B)] = temporary_password_string
Set temporary_password_string = <Empty String>
//This should be outside the loop. Right now it's running 6 times (6 heros are being created).
-------- Create! --------
If (PasswordParts[4] Equal to 1) then do (Unit - Create 1 Paladin for (Triggering player) at ((Triggering player) start location) facing (Center of (Entire map))) else do (Do nothing)
If (PasswordParts[4] Equal to 2) then do (Unit - Create 1 Archmage for (Triggering player) at ((Triggering player) start location) facing (Center of (Entire map))) else do (Do nothing)
If (PasswordParts[4] Equal to 3) then do (Unit - Create 1 Mountain King for (Triggering player) at ((Triggering player) start location) facing (Center of (Entire map))) else do (Do nothing)
Hero - Set (Last created unit) experience to (Integer(PasswordParts[1])), Hide level-up graphics
Player - Set (Triggering player) Current gold to (Integer(PasswordParts[2]))
Player - Set (Triggering player) Current lumber to (Integer(PasswordParts[3]))

I assume all integers are set to zero my default. You should set all variables to zero (integers) or blank (strings) before using them, just to make sure they weren't used before and are not at zero anymore.

Sorry, but I won't look at this again. Reading GUI is too annoying for me.

Use debug messages to double check each thing as it happens. Place game messages all over the place displaying either information on whats happening for each part of your trigger or if your trigger not finishing use simple 123 messages to narrow down the point that its not working.

If this is the save system your going to be using on a map you should look into something better. Like ?Vex's? save system. This is too easy to break.

GUI is not nice to read or write. Try to learn vJASS. Although the learning curve is harder the New Gen World Editor makes learning it much easier with TESH (function lookup) built in. Also you can convert GUI to JASS to see how things are done. I convert stuff all the time because I'm not sure what I'm looking for.