Change a particular clone parameter

Non-platform specific questions.

Change a particular clone parameter

Postby lverona » Mon Apr 20, 2015 11:25 am

When the game starts, I have 30 clones created. Is there a way later on in the game to, say, change yvelocity of a particular clone, say, clone number 26?
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Change a particular clone parameter

Postby koala » Mon Apr 20, 2015 2:40 pm

lverona wrote:When the game starts, I have 30 clones created. Is there a way later on in the game to, say, change yvelocity of a particular clone, say, clone number 26?
Hi, lverona! :D

Global code:
Code: Select all
#define MAX 5 // number of clones
#define NAME 31 // clone's name length

char cloneName[NAME]; // clone's name
Actor *clonePlayer; // pointer to a clone


Global Variables:
- index - clone's index
- acc - initial index value after you press [SPACE]

view -> Create Actor -> Script Editor:
Code: Select all
acc = -MAX; // initialize
When you press [space] first time and start the program, acc will be 0.

choose (text) -> Draw Actor -> Script Editor:
Code: Select all
sprintf(choose.text, "choose clone: %i", index);
This shows index of current clone.
Every frame it activates this code because it is in Draw Actor. Writes string in choose.text.

view -> Key Down (space) -> Repeat: Disable -> Script Editor:
Code: Select all
int i;

// delete all previos clones
for (i = acc; i < acc + MAX; i++) {
    sprintf(cloneName, "player.%d", i);
    DestroyActor(cloneName);
}
// first i goes from 0 to 4, next time i goes from 5 to 9, and so on,
// because when you destroy previous clones and create new, those new clones have their indexes
// new clones will have new indexes

acc += MAX;

index = acc;

// create new clones
for (i = 0; i < MAX; i++)
    CreateActor("player", "square", "no parent", "no path", (i * 100 - 200), 0, true);

// create text and border, but only when game is started
if (acc == 0) {
    CreateActor("choose", "no animation", "no parent", "no path", -280, 200, true);
    CreateActor("border", "no animation", "no parent", "no path", -300, -220, true);
}


Changing index:
When left arrow key is pressed index decreases:
view -> Key Down (left) -> Repeat: Disable -> Script Editor:
Code: Select all
index = (index - 1 < acc) ? acc + 4 : index - 1;

Similarly, when right arrow key is pressed index increase:
view -> Key Down (right) -> Repeat: Disable -> Script Editor:
Code: Select all
index = acc + fmod (index + 1, MAX);


Moving up and down (on y-axis):
Moving up:
view -> Key Down (up) -> Repeat: Enable -> Script Editor:
Code: Select all
sprintf(cloneName, "player.%d", index);

clonePlayer = getclone(cloneName);
(*clonePlayer).y -= 5;

Moving down:
view -> Key Down (down) -> Repeat: Enable -> Script Editor:
Code: Select all
sprintf(cloneName, "player.%d", index);

clonePlayer = getclone(cloneName);
(*clonePlayer).y += 5;


player (main actor) -> Collision: When collides with border_top, or border_bottom activate Physical Response and set Final Velocity Multiplier of Event Actor (player) to 0. This Event needs to be repeated.

border (canvas actor) -> Create Actor -> Script Editor:
Code: Select all
erase(0, 0, 0, 1);

setpen(255, 255, 255, 0, 1);

lineto(width - 2, 0);
lineto(width - 2, height - 2);
lineto(0, height - 2);
lineto(0, 0);
Draw border when canvas actor border is created.

Actors Filled Regions: border_top, border_bottom; border_left and border_right are not necessary because clones move up and down.

Links to files same as in attachments:
executable file:http://www.mediafire.com/download/392q0f6orxf8s70/clone_motion_exe.zip
source (ged and data files):http://www.mediafire.com/download/b61ulbm5cvtt1ry/clone_motion_ged.zip
Attachments
clone_motion_ged.zip
(82.61 KiB) Downloaded 176 times
clone_motion_exe.zip
(795.01 KiB) Downloaded 170 times
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Re: Change a particular clone parameter

Postby MrJolteon » Mon Apr 20, 2015 3:27 pm

koala wrote:tl;dr

Or instead of doing all that, just use the built-in cloneindex variable:
Code: Select all
if(cloneindex == 420)
{
    //whatever you want clone #420 to do
}
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: Change a particular clone parameter

Postby lverona » Mon Apr 20, 2015 5:51 pm

Guys!

Big thanks for the very detailed replies. I had to add more details, but I think part of what you suggested would still be applicable.

So I have 30 clones of an actor.

How can I change yvelocity of clone number 26 from another actor, say, an actor that awaits a button press? So this is not something I can necessarily do from within the clones.

My hunch was that you can do ThatActor.26.yvelocity=3;
But this does not work. You can do ThatActor.yvelocity=3; But it will target the lowest index actor, by default ThatActor.0
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Change a particular clone parameter

Postby MrJolteon » Mon Apr 20, 2015 6:04 pm

lverona wrote:Guys!

Big thanks for the very detailed replies. I had to add more details, but I think part of what you suggested would still be applicable.

So I have 30 clones of an actor.

How can I change yvelocity of clone number 26 from another actor, say, an actor that awaits a button press? So this is not something I can necessarily do from within the clones.

My hunch was that you can do ThatActor.26.yvelocity=3;
But this does not work. You can do ThatActor.yvelocity=3; But it will target the lowest index actor, by default ThatActor.0


Code: Select all
if(actor.cloneindex == 26)
{
    actor.yvelocity=3;
}
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: Change a particular clone parameter

Postby lcl » Tue Apr 21, 2015 12:02 am

Code: Select all
getclone("ThatActor.26")->yvelocity = 3;

It's better to learn to use getclone than to use if checks for cloneindex. Think if you have hundreds of clones and you tell them all to check if their cloneindex is 26 just in order to change that specific clone's yvelocity.. Not efficient.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Change a particular clone parameter

Postby koala » Tue Apr 21, 2015 4:01 am

lverona wrote:When the game starts, I have 30 clones created. Is there a way later on in the game to, say, change yvelocity of a particular clone, say, clone number 26?
Maybe this topic can help you somehow. It doesn't refer to your question, but it uses clones, so it might help. :)
http://game-editor.com/forum/viewtopic.php?f=27&t=13558
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Re: Change a particular clone parameter

Postby lverona » Tue Apr 21, 2015 4:43 am

lcl wrote:
Code: Select all
getclone("ThatActor.26")->yvelocity = 3;



Yes! This is the syntax I was asking about!

But now is there a way to make the number of clone random? I tried variations but could not find a way to incorporate a variable into getclone.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Change a particular clone parameter

Postby lverona » Tue Apr 21, 2015 10:58 am

I tried this, but it does not seem to do anything.

Code: Select all
char random_item[1];
short int ch;

ch=rand(26);

sprintf(random_item, "item1.%d", ch);
getclone(random_item)->yvelocity=-3;
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Change a particular clone parameter

Postby lcl » Tue Apr 21, 2015 12:02 pm

The problem is in your definition of the variable random_item. You've made it to be an array of characters that is only one character long. Then you're trying to store in it something that is either 7 or 8 characters long. And obviously that doesn't work. Make the array to be lengthy enough, put anything bigger than 7 in there and it'll work.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Change a particular clone parameter

Postby lverona » Wed Apr 29, 2015 12:55 pm

Thank you, it worked when I added characters.

char random_item[8];
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Change a particular clone parameter

Postby Zivouhr » Sun May 03, 2015 1:22 pm

This is an awesome thread with very helpful information, and a great first question too! Thank you all. 8)
I was trying to figure out without any references, how to change the color of an individual clone, but I kept trying to code with case 0, case 1 and couldn't get it to work.

clone/create actor/script editor:
Code: Select all
if (cloneindex==22)  // "robot.22" is the one clone of say, 100, that I need to change color or do something.
{
b=-55;
g=235; //both make yellow
}



The GetClone code is also helpful too.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Change a particular clone parameter

Postby lverona » Sun May 24, 2015 2:51 pm

What if I want to use this construction in a MoveTo function? This function will not accept a char.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Change a particular clone parameter

Postby lverona » Sun May 24, 2015 2:55 pm

Also, how do I read variables from a clone?
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Change a particular clone parameter

Postby koala » Sun May 24, 2015 3:46 pm

You read variables form a clone using
getclone(clone_name)->variable

Argument of MoveTo() shouldn't be char, but string. String is an array of chars that ends with '\0'.
You can make a string this way:
Code: Select all
char name[31];

sprintf(name, "clone.%d", clone_num);
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron