Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Creating Mail System  (Read 6244 times)

0 Members and 1 Guest are viewing this topic.

Ryouko

  • Clumpsy, tea loving artist~
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 23
  • Uhm... nothing to say here! =D
    • View Profile
Creating Mail System
« on: February 02, 2012, 06:15:12 PM »

Hey there, again! =D

Since mailing is kinda essential in my game I started to write the... thingy.
But then I noticed that because of my lack of experience I don't know which way is the best.
I kinda tried out this method to fill the window statics:
Code: WME Script
  1. method Mails(Absender, Location, Titel, Inhalt)
  2. {
  3.         var mWin = Game.LoadWindow("interface/mails/mails_main.window"); // load the mail window
  4.         var mSender = mWin.GetControl("sender");
  5.         var mBetreff = mWin.GetControl("betreff");
  6.         var mOrt = mWin.GetControl("ort");
  7.         var mBild = mWin.GetControl("icon");   
  8.        
  9.         var nWin = mWin.GetControl("nWin");
  10.         var mNachricht = nWin.GetControl("nachricht");
  11.                
  12.         var sender = Absender;
  13.        
  14.         mBild.SetImage("interface/mails/icons/"+sender+".png");
  15.        
  16.         mSender.Text = Absender;
  17.         mOrt.Text = Location;
  18.         mBetreff.Text = Titel;
  19.         mNachricht.Text = Inhalt;
  20. }
Which was fine.
But I don't know how to save this - using variables?
I also tried out working with arrays in the window script but this just got messy.

How would you go on about this?
(Or is there already a script like this and I overlooked it?)
I know that it might be early for me to try something like this but I don't have a programmer - and since I gotta do this stuff myself anyway I might as well start.

I'd really appreciate your input!

- R.
« Last Edit: February 03, 2012, 11:20:54 AM by Ryouko »
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Creating Mail System
« Reply #1 on: February 02, 2012, 11:32:45 PM »

what exactly are you trying to achieve? Incoming emails or outgoing emails or both? :)
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Ryouko

  • Clumpsy, tea loving artist~
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 23
  • Uhm... nothing to say here! =D
    • View Profile
Re: Creating Mail System
« Reply #2 on: February 03, 2012, 06:59:48 AM »

Hello, dear. =)

Actually, both.
It would be nice if you could use the response thingy (or something) to choose one from the options what to answer.
(Guess the process would be stored in a variable? So, if you get the first mail of a topic, the var is = 1, then you have two choices, and so the var gets to be either 2 or 3. Something like this?)

- R.
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Creating Mail System
« Reply #3 on: February 04, 2012, 02:46:25 PM »

Ok. Basically you should start with some data structures. The email system could be an object which has an array of objects for incoming and outgoing emails.

Create scripts/mailsystem.script

Code: WME Script
  1. #include "scripts/base.inc"
  2.  
  3. method InitMailSystem()
  4. {
  5.     this.IncomingEmails = new Array();
  6.     this.OutGoingEmails = new Array();
  7. }
  8.  
  9. method CreateEmail(from, to, subject, body, sendDate)
  10. {
  11.     var email;
  12.     email.From = from;
  13.     email.To = to;
  14.     email.Subject  = subject;
  15.     email.Body = body;
  16.     email.SendDate  = sendDate;
  17.     return email;
  18. }
  19.  
  20. method InsertIncomingEmail(from, to, subject, body, sendDate)
  21. {
  22.     var email = CreateEmail(from, to, subject, body, sendDate);
  23.     var emailArray = this.IncomingEmails;
  24.     emailArray.Push(email);
  25.     this.IncomingEmails = emailArray;
  26. }
  27.  
  28. method InsertOutgoingEmail(from, to, subject, body, sendDate)
  29. {
  30.     var email = CreateEmail(from, to, subject, body, sendDate);
  31.     var emailArray = this.OutgoingEmails;
  32.     emailArray.Push(email);
  33.     this.OutgoingEmails = emailArray;
  34. }
  35.  
  36. method GetIncomingEmailsCount()
  37. {
  38.     var emailArray = this.IncomingEmails;
  39.     return emailArray.Length;
  40. }
  41.  
  42. method GetOutgoingEmailsCount()
  43. {
  44.     var emailArray = this.OutgoingEmails;
  45.     return emailArray.Length;
  46. }
  47.  
  48. method GetIncomingEmail(index)
  49. {
  50.     var emailArray = this.IncomingEmails;
  51.     if (index >= emailArray.Length) return null; // we don't have such an email defined
  52.    
  53.     var email = emailArray[index];
  54.     return email;
  55. }
  56.  
  57. method GetOutgoingEmail(index)
  58. {
  59.     var emailArray = this.OutgoingEmails;
  60.     if (index >= emailArray.Length) return null; // we don't have such an email defined
  61.    
  62.     var email = emailArray[index];
  63.     return email;
  64. }
  65.  
  66. }
  67.  
  68.  
  69.  

We put the email system into scripts/base.inc

Code: WME Script
  1.  
  2. global MailSystem;
  3.  
  4.  

Now this object should be initialized in scripts/game.script

Code: WME Script
  1.  
  2. MailSystem = new Object("scripts/mailsystem.script");
  3. MailSystem.InitMailSystem();
  4.  
  5.  


Now whenever you need to insert email, you simply write in some of your scripts:

Code: WME Script
  1.  
  2. MailSystem.InsertIncomingEmail("assassin@killer.com","me@me.me", "I am email subject", "I am email body", "1. 2. 2012");
  3.  
  4. // the same for outgoing emails...
  5.  
  6.  

If you want to loop through all outgoing emails:

Code: WME Script
  1.  
  2. var outgoingCount = MailSystem.GetOutgoingEmailsCount();
  3.  
  4. for (var a=0; a<outgoingCount; a=a+1)
  5. {
  6.     var email = MailSystem.GetOutgoingEmail(a);
  7.     if (email != null)
  8.     {
  9.        /// obviously, this is just for a display. You will probably fill your window components based on this data
  10.        Game.Msg(email.From);
  11.        Game.Msg(email.To);
  12.        Game.Msg(email.Subject);
  13.        Game.Msg(email.Body);
  14.        Game.Msg(email.SendDate);
  15.     }
  16.  
  17. }
  18.  
  19.  

Hope this sets you on the right track...
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Ryouko

  • Clumpsy, tea loving artist~
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 23
  • Uhm... nothing to say here! =D
    • View Profile
Re: Creating Mail System
« Reply #4 on: February 04, 2012, 06:08:40 PM »

metamorphium, you are godlike.
I never thought of making so many methods but it really seems to make sense here!
(Learned something again. <3)

Ah, I have a question though. =o
How do you make a... list of buttons that links to the mails?
I have this problem with a few scripts because I don't have a clue how to do this.

Ignore the graphics, it's still work in progress.
So, what I want to archive is to create a button with the subject as text - I guess these buttons can be created by script when adding a new mail [in the method?] but I don't know how add them in a way that they are ordered vertically.
(You know, like a vertical list.
Button 1
Button 2
Button 3)

Well, don't know if needed, but this is the window script:
Code: WME Script
  1. #include "scripts\base.inc"
  2. #include "scripts\keys.inc"
  3.  
  4. this.xResult = false;
  5.  
  6. var sender = this.GetControl("sender"); // "from" static
  7. var betreff = this.GetControl("betreff"); // "subject" static
  8. var nWin = this.GetControl("nWin"); // window for "body" [clipped to main window to make the text scrollable]
  9. var nachricht = nWin.GetControl("nachricht"); // "body" static
  10. var ort = this.GetControl("ort"); // "location" static
  11. var bWin = this.GetControl("bWin"); // window for buttons [clipped to main window to make them scrollable]
  12.  
  13. var incomingCount = MailSystem.GetIncomingEmailsCount();
  14.  
  15. for (var a=0; a<incomingCount; a=a+1)
  16. {
  17.     var email = MailSystem.GetIncomingEmail(a);
  18.     if (email != null)
  19.     {
  20.            sender.Text = email.From;
  21.        betreff.Text = email.Subject;
  22.        nachricht.Text = email.Body;
  23.        ort.Text = email.Location;
  24.     }
  25.  
  26. }
  27.  
  28. ////////////////////////////////////////////////////////////////////////////////
  29. on "close"
  30. {
  31.   this.Close();
  32. }


Also, thanks again for your help! <3
Don't know what I'd do without you, and your scripting is a huge inspiration for the future. :>

- R.
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Creating Mail System
« Reply #5 on: February 04, 2012, 06:44:47 PM »

I thought you were going to do a Dialogue response list?

Something like:

Code: WME Script
  1.  
  2.  
  3.  
  4. var inboxResponse = 0;
  5.  
  6.  
  7. while (inboxResponse != 1000)
  8. {
  9.  
  10. var numInboxMails = MailSystem.GetIncomingEmailsCount();
  11.  
  12. for (var a = 0; a<numInboxEmails; a = a+1)
  13. {
  14.    var email = MailSystem.GetIncomingEmail(a);
  15.    Game.AddResponse(a, email.Subject);
  16. }
  17.  
  18.   Game.AddResponse(1000, "Exit inbox");
  19.  
  20.   inboxResponse = Game.GetResponse();
  21.  
  22.   DisplayInboxEmail(inbboxResponse); // you would have to write this method which would set statics of your window. :)
  23.  
  24. }
  25.  

Or am I missing something?
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Ryouko

  • Clumpsy, tea loving artist~
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 23
  • Uhm... nothing to say here! =D
    • View Profile
Re: Creating Mail System
« Reply #6 on: February 04, 2012, 07:44:22 PM »

Ah, when I was talking 'bout the response list, I meant when choosing which mail to send. =o
But using the Dialoge response list would also be practical, as long as you could put it inside the main window.
Is there a way to do this?
Code: WME Script
  1. DisplayInboxEmail(inbboxResponse); // you would have to write this method which would set statics of your window. :)
So... This method contains the fillable statics (from, to etc.) or something else?
I kinda tried this but I'm afrait I failed.
Window script:
Code: WME Script
  1. #include "scripts\base.inc"
  2. #include "scripts\keys.inc"
  3.  
  4. function Inbox()
  5. {
  6.         Game.StartDlgBranch("Inbox");
  7.  
  8.         var inboxResponse = 0;
  9.  
  10.         while (inboxResponse != 1000)
  11.         {
  12.  
  13.                 var numInboxMails = MailSystem.GetIncomingEmailsCount();
  14.  
  15.                 for (var b = 0; b<numInboxMails; b = b+1)
  16.                 {
  17.                 var email = MailSystem.GetIncomingEmail(b);
  18.                 Game.AddResponse(b, email.Subject);
  19.                 }
  20.  
  21.                 Game.AddResponse(1000, "Exit inbox");
  22.  
  23.                 inboxResponse = Game.GetResponse();
  24.  
  25.                 DisplayInboxEmail(inboxResponse); // you would have to write this method which would set statics of your window. :)
  26.  
  27.         }
  28.         Game.EndDlgBranch();
  29. }
  30.  
  31. this.xResult = false;
  32.  
  33. /*
  34. var sender = this.GetControl("sender"); // "from" static
  35. var betreff = this.GetControl("betreff"); // "subject" static
  36. var nWin = this.GetControl("nWin"); // window for "body" [clipped to main window to make the text scrollable]
  37. var nachricht = nWin.GetControl("nachricht"); // "body" static
  38. var ort = this.GetControl("ort"); // "location" static
  39. var bWin = this.GetControl("bWin"); // window for buttons [clipped to main window to make them scrollable]
  40.  
  41. var incomingCount = MailSystem.GetIncomingEmailsCount();
  42. for (var a=0; a<incomingCount; a=a+1)
  43. {
  44.     var email = MailSystem.GetIncomingEmail(a);
  45.     if (email != null)
  46.     {
  47.            sender.Text = email.From;
  48.        betreff.Text = email.Subject;
  49.        nachricht.Text = email.Body;
  50.        ort.Text = email.Location;
  51.     }
  52.  
  53. }
  54. */
  55. Inbox();
  56.  
  57. ////////////////////////////////////////////////////////////////////////////////
  58. on "close"
  59. {
  60.   this.Close();
  61. }
  62. ////////////////////////////////////////////////////////////////////////////////
  63.  
Method, in the mailsystem:
Code: WME Script
  1.  
  2. method DisplayInboxEmail(inboxResponse)
  3. {
  4.        
  5.         var mailWin = Game.LoadWindow("interface/mails/mails_main.window");
  6.         var sender = mailWin.GetControl("sender"); // "from" static
  7.         var betreff = mailWin.GetControl("betreff"); // "subject" static
  8.         var nWin = mailWin.GetControl("nWin"); // window for "body" [clipped to main window to make the text scrollable]
  9.         var nachricht = nWin.GetControl("nachricht"); // "body" static
  10.         var ort = mailWin.GetControl("ort"); // "location" static
  11.         var bWin = mailWin.GetControl("bWin"); // window for buttons [clipped to main window to make them scrollable]
  12.        
  13.         var incomingCount = MailSystem.GetIncomingEmailsCount();
  14.         for (var a=0; a<incomingCount; a=a+1)
  15.         {
  16.                 var email = MailSystem.GetIncomingEmail(a);
  17.                 if (email != null)
  18.                 {
  19.                 sender.Text = email.From;
  20.                 betreff.Text = email.Subject;
  21.                 nachricht.Text = email.Body;
  22.                 ort.Text = email.Location;
  23.                 }
  24.         }
  25.  
What is the right way? =o

- R.
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Creating Mail System
« Reply #7 on: February 04, 2012, 07:48:28 PM »

Is the email function part of some specific scene or is it something you can access always?
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Ryouko

  • Clumpsy, tea loving artist~
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 23
  • Uhm... nothing to say here! =D
    • View Profile
Re: Creating Mail System
« Reply #8 on: February 04, 2012, 07:54:31 PM »

It's something you can always access from the menu. =o
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Creating Mail System
« Reply #9 on: February 04, 2012, 08:43:12 PM »

Okay. It seems we're slowly getting somewhere. My main concern now is - what do you want to place in the vertical bar? It's very narrow to have any kind of reasonable information. Could you please post an image of the target window example? Kind of pseudo-sample from the game. Also do you plan to have more emails than the vertical part can hold? (you'd need up and down arrows for that).

Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Ryouko

  • Clumpsy, tea loving artist~
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 23
  • Uhm... nothing to say here! =D
    • View Profile
Re: Creating Mail System
« Reply #10 on: February 04, 2012, 09:21:00 PM »

The vertical bar is supposed to contain the subjects, so that you can choose the mail which will be displayed. =o
(Well, it might really be a little bit narrow. I might make it a little bit wider later.)
Quote
Could you please post an image of the target window example?
The... target window?
What exactly do you want? (Sorry, I'm really, really slow today. Dx)
An image from WindowEdit or the project or a code or...?

Quote
Also do you plan to have more emails than the vertical part can hold? (you'd need up and down arrows for that).
Jop~
I read that WME automatically recognises buttons with the name "up" and "down" or something?
Or is there still some script that's needed to be written?

Thank you for your patience~ :>

- R.
Logged
 

Page created in 0.105 seconds with 20 queries.