Reply to this subject
Start a new subject
 
Refresh page
Pages: 1
2
3
4
5
| Posted by |
Tsunami
USA (204 posts) bio
|
| Date |
Reply #60 on Tue 06 Feb 2007 05:09 AM (UTC) [ quote
] |
| Message |
| The assumption is that temp_afflicted is created somewhere else in the script, and that this is appropriately checked. You could equally set it equal to {} instead of nil. | top |
|
| Posted by |
Caelan
Vanuatu (12 posts) bio
|
| Date |
Reply #61 on Tue 06 Feb 2007 11:51 AM (UTC) [ quote
] |
| Message |
So would this work since it depends on the IF?
function temp_toreal ()
lifevision = GetVariable("lifevision")
-- see if it picked up lifevision
if (lifevision == true) then
temp_aff = {}
return
end -- if
elseif (lifevision == false)
for k in pairs (temp_aff) do
afflicted(k)
end -- for
end -- if
end -- function
temp_aff is the table. temp_afflicted would be a function similar to the previous 'afflicted' one to assign the afflictions to the temp_aff table. If lifevision is true, I want all afflictions (would be 2 or 3 tops) cleared out of the temp_aff table. | top |
|
| Posted by |
Tsunami
USA (204 posts) bio
|
| Date |
Reply #62 on Tue 06 Feb 2007 03:41 PM (UTC) [ quote
] |
| Message |
The idea is right, but there are a couple syntax problems.
if (lifevision == true) then
temp_aff = {}
return
end
the 'end' right there closes the if statement. This means that you can't continue it with the elseif. Because of the return statement, you can eliminate the elseif altogether. If the script execution gets to that point, it is guarenteed lifevision is false; if not, it would have returned from the function.
| top |
|
| Posted by |
Nick Gammon
Australia (18,769 posts) bio
Forum Administrator |
| Date |
Reply #63 on Tue 06 Feb 2007 06:42 PM (UTC) [ quote
] |
| Message |
Quote:
lifevision = GetVariable("lifevision")
-- see if it picked up lifevision
if (lifevision == true) then
You haven't addressed here my concerns expressed earlier about variable types. You are using "true" here which is a boolean type, but GetVariable returns a string type. These are two different data types, and thus the expression " (lifevision == true)" will always be false. That is, it will never execute the code inside that 'if".
I suggest you play around with Lua a bit to get a feel for the syntax, perhaps a simple program in the Immediate window to print a list of numbers and multiply them by 2, something like that. Then you will feel more comfortable tackling more complex problems.
Quote:
The assumption is that temp_afflicted is created somewhere else in the script, and that this is appropriately checked.
It is my experience that it is usually assumptions that bring programs undone.
The code below should be syntactically correct, whether it works or not depends on what the variables are used for elsewhere:
function temp_toreal ()
-- see if it picked up lifevision
if GetVariable ("lifevision") == "1" then
temp_aff = {}
return
end -- if
for k in pairs (temp_aff) do
afflicted (k)
end -- for
end -- function
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
19,763 views.
This is page 5, subject is 5 pages long:
1
2
3
4
5
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )