Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Pages: [1] 2  All

Author Topic: Cell phone  (Read 14578 times)

0 Members and 1 Guest are viewing this topic.

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Cell phone
« on: August 25, 2007, 04:04:04 PM »

Hi again,

I'm trying to make a cell phone that can be used in game to call other characters. So I basically have a "cell phone" scene, with an image of the cell phone, and I have region entities for each button, and various background images for the different menus and phone screens. I think changing the screen images is no problem, for example, clicking on the "contacts" button changes the screen to the contacts screen.

But, I'm having trouble understanding how to have the numbers displayed. I want the player to click the number keys and then for the number to come up on the screen like a cell phone would. So if they click 0, then a 0 is displayed, then they click 7, and the 7 is displayed but at the same time, the 0 is moved to the left to make room for the 7, and so on and so on.

Any tips how i can do this? Any idea where I can start? Should I use some kind of window for the whole phone screen? I'm thinking when they press 0, the game will display the 0 as text, and then when they press 7, the game will display "this" + "this", which will show 07, etc etc, but I don't know where to start with that. And then I need some way to recognise the number that's been entered so that when they press the green button on the phone, the game knows which conversation script to run.

Thanks.  8)
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Cell phone
« Reply #1 on: August 25, 2007, 05:20:32 PM »

Yes, to will need to use a window with a static control to display the text, and modify the text when the keys are pressed.

Some time ago I scripted a simple cell phone for one game, and since the game's probably not going to be finished, I'm releasing the code to public domain: http://dead-code.org/download/demos/cell_phone.zip

It may be overly complicated for your purposes, but studying the script could give you some ideas.
See the enclosed readme.txt for usage instructions.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Cell phone
« Reply #2 on: August 25, 2007, 09:22:04 PM »

Thanks man. Very useful indeed. 8)

I think I'm beginning to understand this "simple" cell phone of yours. I've already changed the numbers so they appear from the right instead of left, so hopefully I can figure it all out.

If this is simple, I'd hate to see something you considered complex.  ;D
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Cell phone
« Reply #3 on: August 26, 2007, 08:26:04 PM »

Hehe, I meant the phone functions were simple, not the script :)
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Cell phone
« Reply #4 on: August 27, 2007, 04:06:43 AM »

Ok, I've basically got most things working, but now I'm having a little trouble doing one thing.

When I select a contact with the "action" button, I want to display that contact's name and number and THEN dial the number when "action" is pressed again a second time.

I think I can work this out, if I can understand some other things first. For example, I don't understand how the square brackets have been used, or why, in this instance:

CallContact(NumberItems[SelectedItem]);

This is going to run the "CallContact" function, using a value generated by NumberItems[SelectedItem]...? And so I guess this is how it knows which contact to call, but I don't fully understand how it knows which contact to call.  :(  If I can understand that, I can probably understand how to display the contact's name and number before calling it.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Cell phone
« Reply #5 on: August 27, 2007, 02:29:23 PM »

The script uses several arrays of items (MenuItems, NumberItems, SmsItems). These arrays are filled by the AddMenu(), AddNumber() and AddSms() functions. It also keeps track of the selected item (the SelectedItem variable).

So "NumberItems[SelectedItem]" returns one of the items stored in the NumberItems array and it passes the result to the CallContact() function.
The SelectedItem variable is updated as the player browses through the phone menus.


The square brackets are used to access a member by its name/number. For example, the following two commands are equivalent:
Code: WME Script
  1. var ActorName = actor.Name;
  2. var ActorName = actor["Name"];
  3.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Cell phone
« Reply #6 on: August 27, 2007, 02:45:36 PM »

So, for example:

Code: [Select]
NumberItems[Count] = Item;
NumberItems.Count = Count + 1;

...are the same thing, except they equal different values? I mean saying NumberItems[Count] is the SAME as saying NumberItems.Count?

 ??? I'm getting confused.  :D
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Cell phone
« Reply #7 on: August 27, 2007, 02:54:16 PM »

Nope, NumberItems.Count is the same as NumberItems["Count"] (you're querying a property called "Count").

NumberItems[Count] queries a property with the name of whatever the Count variable contains.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Cell phone
« Reply #8 on: August 27, 2007, 03:42:37 PM »

Ok, I'm getting there slowly.

Do you think you could quickly explain what happens with the AddNumber code, in terms of the arrays, and the Count thing...?

Code: [Select]
function AddNumber(Name, Number, ID)
{
var Count = NumberItems.Count;
if(Count==null) Count = 0;

var Item;
Item.Text = Name;
Item.Number = Number;
Item.ID = ID;

NumberItems[Count] = Item;
NumberItems.Count = Count + 1;
}

So, it adds the 3 values to an array?

And then the NumberItems.Count is the total amount of actual "numbers" i have added? So if I've added 10 numbers, the NumberItems.Count would be 10? And NumberItems.Count = Count + 1 is adding 1 more to the total amount because I've just added a new number, which would mean it equalled 11 after this code has run?

So then what does NumberItems[Count] = Item represent in this case?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Cell phone
« Reply #9 on: August 27, 2007, 05:08:39 PM »

It creates a new address book item ("Item") and fills its properties (Text, Number, ID). Then it adds the newly created item to the NumberItems array at the "Count" index and increases the count (so that next time you add an item, if will get a higher number).

You can try looking the arrays up in the WME debugging console, it should make things much clearer.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Cell phone
« Reply #10 on: August 27, 2007, 05:51:56 PM »

Thanks for the help.  :)

I've managed to do what I need. I still don't fully understand everything, and the scripting is probably not 100% correct, but if it works, it works right?  8)  ::beer

One more thing I wanted to ask about. If I want to add new numbers, messages etc etc later on in the game, after certain things have happened, how can I do that? Is there a way to insert the AddNumber etc into the phone.script from another script? Or should I create a global variable and check this at the start of phone.script and add whatever I need depending on the variable?

Thanks again.
« Last Edit: August 27, 2007, 05:54:51 PM by TheDerman »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Cell phone
« Reply #11 on: August 27, 2007, 08:29:22 PM »

Yes, you'll need to use variables and do the branching in phone.script, because all the phone related stuff is only loaded as long as the phone is displayed.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Cell phone
« Reply #12 on: August 28, 2007, 07:35:05 PM »

Thanks.

Have another little problem now. I made a new mode, called "in_call", and when the script is running the DoCall function and playing the dialing sound, I made it so that clicking on "cancel" returns the screen to the main screen, which makes it seem like the call has been cancelled. But, the script is still running the DoCall function, even when we're back on the main phone screen.

So, how can I stop the function halfway through? I tried putting "return" in the "cancel" script but that didn't work.

Thanks.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Cell phone
« Reply #13 on: August 28, 2007, 08:56:34 PM »

You'd need to employ some variable. The DoCall function would be checking the value of the variable from time to time (e.g. between the dialing tones), and the "cancel" button handler would just set the variable to true.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

TheDerman

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 225
    • View Profile
Re: Cell phone
« Reply #14 on: August 28, 2007, 10:28:11 PM »

Woohoo - added a few more "modes" and some loops, and now it's done.  ;D

Thanks Mnemonic - this phone script is excellent - just what I wanted.  ::rock
Logged
Pages: [1] 2  All
 

Page created in 0.029 seconds with 18 queries.