Noob array question

Post » Fri Feb 18, 2011 11:07 pm

Would this be valid:

array_var aTimeBegin GameMode		Let aTime := ar_Construct StringMap	Let aTime := GetUserTime        Let aTime[0] := aTime ["DayofWeek"]        ...

User avatar
Breanna Van Dijk
 
Posts: 3384
Joined: Mon Mar 12, 2007 2:18 pm

Post » Fri Feb 18, 2011 10:51 pm

No.

http://cs.elderscrolls.com/constwiki/index.php/Introduction_to_OBSE_arrays may help you here.
User avatar
Siobhan Wallis-McRobert
 
Posts: 3449
Joined: Fri Dec 08, 2006 4:09 pm

Post » Fri Feb 18, 2011 10:48 pm

Okay, thanks. I've read that before, but, through an example, have learned more about arrays. I'll re-read it now that I understand more.
User avatar
Samantha Pattison
 
Posts: 3407
Joined: Sat Oct 28, 2006 8:19 pm

Post » Sat Feb 19, 2011 10:57 am

This isn't a finished script, but is there a more efficient way to do what I have done?

string_var svDayoftheWeekstring_var svMontharray_var aTimefloat fMonthfloat fDayofWeekfloat fDayfloat fHourfloat fMinuteBegin GameMode		Let aTime := ar_Construct StringMap	Let aTime := GetUserTime	Let fMonth := aTime["Month"]	Let fDayofWeek := aTime["DayofWeek"]	Let fDay := aTime["Day"]	Let fHour := aTime["Hour"]	Let fMinute := aTime["Minute"]		If fDayofWeek == 1		Let svDayoftheWeek := "Sunday"	EndIf		If fDayofWeek == 2		Let svDayoftheWeek := "Monday"	EndIf		If fDayofWeek == 3		Let svDayoftheWeek := "Tuesday"	EndIf		If fDayofWeek == 4		Let svDayoftheWeek := "Wednesday"	EndIf		If fDayofWeek == 5		Let svDayoftheWeek := "Thursday"	EndIf		If fDayofWeek == 6		Let svDayoftheWeek := "Friday"	EndIf		If fDayofWeek == 7		Let svDayoftheWeek := "Saturday"	EndIf		If fMonth == 1		Let svMonth := "January"	EndIf		If fMonth == 2		Let svMonth := "February"	EndIf		If fMonth == 3		Let svMonth := "March"	EndIf		If fMonth == 4		Let svMonth := "April"	EndIf		If fMonth == 5		Let svMonth := "May"	EndIf		If fMonth == 6		Let svMonth := "June"	EndIf		If fMonth == 7		Let svMonth := "July"	EndIf		If fMonth == 8		Let svMonth := "August"	EndIf		If fMonth == 9		Let svMonth := "September"	EndIf		If fMonth == 10		Let svMonth := "October"	EndIf		If fMonth == 11		Let svMonth := "November"	EndIf		If fMonth == 12		Let svMonth := "December"	EndIf		MessageBoxEx "%z %z %.0f %.0f %.0f", svDayoftheWeek, svMonth, fDay, fHour, fMinute	End

User avatar
michael flanigan
 
Posts: 3449
Joined: Thu Jun 14, 2007 2:33 pm

Post » Sat Feb 19, 2011 5:37 am

On you example, the first line is not necessary because there is no need to initialize the array since the next line will reset it, anyway.

You may simplify it a bit

        If fDayofWeek == 1                 Let svDayoftheWeek := "Sunday"         elseIf fDayofWeek == 2                 Let svDayoftheWeek := "Monday"         elseIf fDayofWeek == 3                 Let svDayoftheWeek := "Tuesday"         elseIf fDayofWeek == 4                 Let svDayoftheWeek := "Wednesday"         elseIf fDayofWeek == 5                 Let svDayoftheWeek := "Thursday"         elseIf fDayofWeek == 6                 Let svDayoftheWeek := "Friday"         elseIf fDayofWeek == 7                 Let svDayoftheWeek := "Saturday"         EndIf                  If fMonth == 1                 Let svMonth := "January"         elseIf fMonth == 2                 Let svMonth := "February"         elseIf fMonth == 3                 Let svMonth := "March"         elseIf fMonth == 4                 Let svMonth := "April"         elseIf fMonth == 5                 Let svMonth := "May"         elseIf fMonth == 6                 Let svMonth := "June"         elseIf fMonth == 7                 Let svMonth := "July"         elseIf fMonth == 8                 Let svMonth := "August"         elseIf fMonth == 9                 Let svMonth := "September"         elseIf fMonth == 10                 Let svMonth := "October"         elseIf fMonth == 11                 Let svMonth := "November"         elseIf fMonth == 12                 Let svMonth := "December"         EndIf 


Or, a more elegant approach (just to tease you, lol):

string_var svDayoftheWeek string_var svMonth array_var aTime array_var aDaysarray_var aMonths float fDay float fHour float fMinute  Begin GameMode         If aDays == 0                Let aDays := ar_Construct Map                 Let aDays[1] := "Sunday"                 Let aDays[2 := "Monday"                 Let aDays[3] := "Tuesday"                 Let aDays[4] := "Wednesday"                 Let aDays[5] := "Thursday"                 Let aDays[6] := "Friday"                 Let aDays[7] := "Saturday"                 Let aMonths := ar_Construct Map                Let aMonths[1] := "January"                 Let aMonths[2] := "February"                 Let aMonths[3] := "March"                 Let aMonths[4] := "April"                 Let aMonths[5] := "May"                 Let aMonths[6] := "June"                 Let aMonths[7] := "July"                 Let aMonths[8] := "August"                 Let aMonths[9] := "September"                 Let aMonths[10] := "October"                 Let aMonths[11] := "November"                 Let aMonths[12] := "December"         EndIf         Let aTime := GetUserTime         Let svMonth := aMonths[aTime["Month"]]        Let svDayofWeek := aDays[aTime["DayofWeek"]]        Let fDay := aTime["Day"]         Let fHour := aTime["Hour"]         Let fMinute := aTime["Minute"]                  MessageBoxEx "%z %z %.0f %.0f %.0f", svDayoftheWeek, svMonth, fDay, fHour, fMinute          End

User avatar
Ymani Hood
 
Posts: 3514
Joined: Fri Oct 26, 2007 3:22 am

Post » Sat Feb 19, 2011 11:28 am

lol

Scripting over my head. But I like the more elegant approach. I'll borrow your script for the mod I'm going to release. I'll credit you.

Plus, I like to see examples, because that's how I learn, through seeing what other people do.

So I must give you an extra sincere thanks you, for two things.
User avatar
Horse gal smithe
 
Posts: 3302
Joined: Wed Jul 05, 2006 9:23 pm

Post » Fri Feb 18, 2011 10:47 pm

Should I destory the string variables after the mod executes to prevent save game bloat?
User avatar
Horror- Puppe
 
Posts: 3376
Joined: Fri Apr 13, 2007 11:09 am

Post » Fri Feb 18, 2011 8:14 pm

Should I destory the string variables after the mod executes to prevent save game bloat?

If you ever use OBSE user defined functions, then it is absolutely mandatory that you destroy any string variables assigned within that user function, each time it is called. If not, one additional copy of the string gets stored in your savegame for each call. Other strings are not important to destroy, as there will not be more than the number of string variables you have, but if you have long arrays with many strings, it may be a good idea to destroy it when you can.
User avatar
Sophie Payne
 
Posts: 3377
Joined: Thu Dec 07, 2006 6:49 am

Post » Sat Feb 19, 2011 7:26 am

You can make it even simpler if you want:
array_var daysarray_var monthslet days := ar_list  "NONE", "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" let months := ar_list "NONE", "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"

User avatar
Rude_Bitch_420
 
Posts: 3429
Joined: Wed Aug 08, 2007 2:26 pm

Post » Sat Feb 19, 2011 11:04 am

If you ever use OBSE user defined functions, then it is absolutely mandatory that you destroy any string variables assigned within that user function, each time it is called. If not, one additional copy of the string gets stored in your savegame for each call. Other strings are not important to destroy, as there will not be more than the number of string variables you have, but if you have long arrays with many strings, it may be a good idea to destroy it when you can.


Okay. So, there probably isn't a need to destroy the strings for this script.
Thanks.

You can make it even simpler if you want:
array_var daysarray_var monthslet days := ar_list  "NONE", "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" let months := ar_list "NONE", "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"



Righto, scruggsy. I'll add that change into the script.
Thanks.
User avatar
I’m my own
 
Posts: 3344
Joined: Tue Oct 10, 2006 2:55 am

Post » Sat Feb 19, 2011 10:45 am

I'm struggling a little bit with a solution. I want to convert the hours and minutes returned by GetUserTime into the correct time that most people are used to. For instance, hour 0 == 12AM, hour 13 == 1 PM. etc. But I want to be efficient and use an array. Could someone start me off on the right track to doing that. I can do it the "vanilla" way with no problems, but that will unnecessarily bloat my script, now that I have these cool arrays going.

Plus, seeing more array examples, in which I know what is trying to be accomplished, will help me learn.

Thanks.
User avatar
Mike Plumley
 
Posts: 3392
Joined: Wed Sep 05, 2007 10:45 pm

Post » Sat Feb 19, 2011 1:49 am

While it could certainly be done with some simple math calculations, why not going the same way scruggs was and using an ar_List like these to map hours 0 - 23 to strings "12 AM" - "11 PM" likewise?
You could then use "let humanreadableHour := AMPMmapping[hourInNumbers]".
User avatar
lucile davignon
 
Posts: 3375
Joined: Thu Mar 22, 2007 10:40 pm

Post » Sat Feb 19, 2011 4:34 am

Yeah, I read the Wiki article about A.M. P.M. conversions. But that produces 4.30 for 4:30 A.M./P.M.. Plus I already have a string for the minutes, so I don't need to calculate minutes from total hours. So, that tutorial doesn't really help.

I'll see if I can't take your suggestion and apply it.

Thanks.
User avatar
No Name
 
Posts: 3456
Joined: Mon Dec 03, 2007 2:30 am

Post » Fri Feb 18, 2011 9:39 pm

You da man, DraketheDragon! Works like a charm.
User avatar
Phillip Hamilton
 
Posts: 3457
Joined: Wed Oct 10, 2007 3:07 pm

Post » Sat Feb 19, 2011 1:22 am

Would this be a valid "Eval" condition:

If Eval (ar_Next  == )      -Do stuff-


to set a condition for the keys following the evaluation?
User avatar
Gemma Woods Illustration
 
Posts: 3356
Joined: Sun Jun 18, 2006 8:48 pm

Post » Sat Feb 19, 2011 11:03 am

I guess to be more to the point, what would be the expression used to == "through"

I want to execute code through a range of array keys. When that range no longer exists, I want to change the code.

EDIT

No. Let me erase that embarrassing example. Let me read the OBSE documentation some more.
User avatar
lauren cleaves
 
Posts: 3307
Joined: Tue Aug 15, 2006 8:35 am

Post » Fri Feb 18, 2011 9:00 pm

EDIT

Nope nope. Didn't work the way I thought it would.
User avatar
yermom
 
Posts: 3323
Joined: Mon Oct 15, 2007 12:56 pm

Post » Sat Feb 19, 2011 4:32 am

I want to refine what I did using a ForEach loop to iterate through the array. How do I tell the loop to stop at a certain key?
User avatar
Rachel Hall
 
Posts: 3396
Joined: Thu Jun 22, 2006 3:41 pm

Post » Sat Feb 19, 2011 3:58 am

Or a while loop. Whatever. Basically I want to walk through the array and stop at a certain key. During those steps, I set a string. During the remainder of the array (the rest of the keys), I set the same string to a different value.

Remember that I am a uber noob. There's still tons I don't understand.
User avatar
Robyn Howlett
 
Posts: 3332
Joined: Wed Aug 23, 2006 9:01 pm

Post » Sat Feb 19, 2011 7:16 am

Just struck me. I could assign the elements I want to another array, assign the rest of the elements to a third array.
User avatar
Monika Krzyzak
 
Posts: 3471
Joined: Fri Oct 13, 2006 11:29 pm

Post » Sat Feb 19, 2011 1:26 am

Check the Break function in the OBSE doc.

It is used to exit a While or ForEach loop immediately, which seems to be what you want.
User avatar
Nicholas C
 
Posts: 3489
Joined: Tue Aug 07, 2007 8:20 am

Post » Fri Feb 18, 2011 10:25 pm

I was overthinking (if that's possible for me) the problem. The solution is very very simple. I'm not going to post what the problem was (ego), but the solution is so much simpler than I thought it would be.
User avatar
Lloyd Muldowney
 
Posts: 3497
Joined: Wed May 23, 2007 2:08 pm


Return to IV - Oblivion