Three questions:
Messaging
How do i message other scripts? I can see that there ID and all the messages are based somewhere, but where?
Randomness
I've seen the random number maker, but how would i do something like this:
Code:
Die
{
obj.getrandomnumber.somehow.(1,6)
if number generated=1
{Play.Animation.die1.}
if number generated=2
{Play.Animation.die2.}
if number generated=3
{Play.Animation.die3.}
if number generated=4
{Play.Animation.die4.}
if number generated=5
{Play.Animation.die5.}
if number generated=6
{Play.Animation.die6.}
}
Picking Your Player
I'd like to make it so that at the start of each multiplayer game you get to choose your players model. Would i do this with chooser somehow? Can you all tell me please?
I'm going to answer all of these in seperate posts to keep it a little... cleaner.
Messaging
To send a message use:
Code:
(game/course/obj/etc).event.
and then any of the following:
sendMessage(to,name,messageId);
sendMessageToPlayer(messageId);
sendMessageToHeldWeapon(messageId);
sendMessageToSpawnWeapon(messageId);
sendMessageToObjectById(objectId,messageId);
sendMessageToObjectByName(objectName,messageId);
sendMessageToCourse(messageId);
sendMessageToGame(messageId);
The script you sent it to, will then receive a DIM3_EVENT_MESSAGE event.
You will have to add a message function, that is called when this happens. (In the event function)
Now you just create a switch in that function, that acts depending on messageId.
That's it.

Randomness
To get a random number between min and max, use
Code:
utility.random.getInteger(min,max);
Now if you want your script to play different die animations, do this:
Code:
var dieAnim = utility.random.getInteger(1,6); //set dieAnim to a random number between 1 and 6
obj.model.animation.start("die" + dieAnim); //start Anim "die" + the number of dieAnim

Picking your player
Don't know much about how choosers work, but I'm going to be needing this too, so... I tried to find out about this.
You start a chooser with
Code:
iface.interaction.startChooser(name);
.
When any element of the chooser was selected, the script you started the chooser from will receive the DIM3_EVENT_CHOOSER event, so add it to the event function and make it call some sort of chooser function.
Make sure to pass "id" to the function, because that's the id of the element that was clicked. The code would be something like
Code:
function event(obj,mainEvent,subEvent,id,tick)
{
switch (mainEvent) {
case DIM3_EVENT_CHOOSER:
playerChooserSelected(id);
return;
}
}
The function "playerChooserSelected" would be something like:
Code:
function playerChooserSelected(id) {
switch(id) {
case 1:
//what to do when element with id 1 is pressed
return;
case 2:
//etc.
return;
}
}
You'd then set a variable that later changes the player model... or whatever you want it to do.
Okay, i get the first two, but:
Quote:You'd then set a variable that later changes the player model... or whatever you want it to do.
If i did:
Code:
function playerChooserSelected(id) {
switch(id) {
case 1:
var model=1
case 2:
var model=2
Would that mean that in the construct i'd put "obj.model=("player" + model)?
Quote:Make sure to pass "id" to the function
I don't know how to "pass" something, what does that mean?
EDIT: btw, imho bink your a legend.
Typewriter Wrote:Okay, i get the first two, but:
Quote:You'd then set a variable that later changes the player model... or whatever you want it to do.
If i did:
Code:
function playerChooserSelected(id) {
switch(id) {
case 1:
var model=1
case 2:
var model=2
Would that mean that in the construct i'd put "obj.model=("player" + model)?
Yeah. Though you will have to set the variable before the construct function is called, since you can't change the model later.
I'd do it somewhere in the game script, store the variable using data.add(name,value); and then retrieve it in the player script, using data.get(name);
Quote:Quote:Make sure to pass "id" to the function
I don't know how to "pass" something, what does that mean?
It means "giving" the function the variable. For example:
Code:
function printNumber(num) { //This is a function that prints the value passed to it (num)
iface.console.write(num); //Write num to console
}
var number = 1; //set number to 1
printNumber(number); //call the printNumber function and pass it the number variable
will write 1 to the console.
Note that in a switch() function, if you have more code you want to put in its parent function after the switch() you're going to want to use break; after each item instead of return;
Code:
function doSwitch(obj) {
// some code maybe
switch(foo) {
case 1:
// do this
break;
case 2:
// do this instead
break;
default:
// do this if not any of the above (optional)
break;
}
// more code here maybe
}
Thanks Teh1ghool, that must be the current problem.
With any part that says id, do i just have id, or make up an id?
You just need id.
id has a number set to it, so when you say switch(id) it is checking what id is. If you said switch(0) it would either return and error, or return case 0 every single time.
These are the variables for the items in a particular chooser; they are found in Game.js:
Code:
var CHOOSER_ITEM_DEMO_MAP=100;
var CHOOSER_ITEM_DEATHMATCH_MAP=101;
var CHOOSER_ITEM_CTF_MAP=102;
This is the function:
Code:
gameChooserSelect(id)
{
switch (id) {
case CHOOSER_ITEM_DEMO_MAP:
map.action.setMap('Demo','Start','Player');
return;
case CHOOSER_ITEM_DEATHMATCH_MAP:
map.action.setMap('Arena','Start','Player');
return;
case CHOOSER_ITEM_CTF_MAP:
map.action.setMap('Red Blue House','Start','Player');
return;
}
}
Take a look at Interface.xml for more insight as to how to set your own items. Hope this helps you!
NOTE: These are the DEFAULT settings; if you like I can display for you the code I used to script my own choosers when I have more time; keep in mind though I was using a lower version (2.3 b8) I can also show you, if you wish, how to set your own menu items (it's pretty much the same way almost, just look at the top of Game.js and be sure to edit the Interface.xml accordingly), but you probably already know how....