Solved random palette

Question that is answered or resolved.

DD Tokki

Well-known member
C:
spawn        Lynn-L1
map        1
coords        -320 190
at        0

This is part of the stage setup.
I would like to have the palette applied randomly when the character spawns.
There are 10 colors.
 
Solution

I applied the script, but the game crashes.
Sorry, it's my fault to write a small typo in the "getlocalvar" command, like the log says.

C:
spawn        Shermie-L1
@script
void main()
{
    int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
    if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
    changeentityproperty(getlocalvar("self"), "map", palette); //APPLY THE PALETTE
}
@end_script
coords        -20 174
at            400
C:
spawn        Lynn-L1
map        1
coords        -320 190
at        0

This is part of the stage setup.
I would like to have the palette applied randomly when the character spawns.
There are 10 colors.
You can use the following script during the spawn.

C:
int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
changeentityproperty(self, "map", palette); //APPLY THE PALETTE
 
You can use the following script during the spawn.

C:
int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
changeentityproperty(self, "map", palette); //APPLY THE PALETTE
C:
spawn        Shermie-L1
map
@script
   int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
   if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
   changeentityproperty(self, "map", palette); //APPLY THE PALETTE
@end_script
coords        -20 174
at        400

Can I apply the script like this?
 
C:
spawn        Shermie-L1
map
@script
   int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
   if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
   changeentityproperty(self, "map", palette); //APPLY THE PALETTE
@end_script
coords        -20 174
at        400

Can I apply the script like this?
In case you are adding directly in the level file, try this way.

C:
spawn        Shermie-L1
@script
void main()
{
    int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
    if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
    changeentityproperty(getlovalvar("self"), "map", palette); //APPLY THE PALETTE
}
@end_script
coords        -20 174
at            400
 
In case you are adding directly in the level file, try this way.

C:
spawn        Shermie-L1
@script
void main()
{
    int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
    if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
    changeentityproperty(getlovalvar("self"), "map", palette); //APPLY THE PALETTE
}
@end_script
coords        -20 174
at            400

I applied the script, but the game crashes.
 

I applied the script, but the game crashes.
Sorry, it's my fault to write a small typo in the "getlocalvar" command, like the log says.

C:
spawn        Shermie-L1
@script
void main()
{
    int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
    if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
    changeentityproperty(getlocalvar("self"), "map", palette); //APPLY THE PALETTE
}
@end_script
coords        -20 174
at            400
 
Solution
Sorry, it's my fault to write a small typo in the "getlocalvar" command, like the log says.

C:
spawn        Shermie-L1
@script
void main()
{
    int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
    if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
    changeentityproperty(getlocalvar("self"), "map", palette); //APPLY THE PALETTE
}
@end_script
coords        -20 174
at            400
KoR - 0078.png

thank you Now with this script you will encounter new colored enemies every time you play the game.
 
Nice. If you don't want your script tags to be redundant with the same scripts, you can use spawnscript for spawning entities in levels. I just renamed this spawnscript file into "randpal.c" for avoiding script redundancy. But for spawning specifics, I use script tags without depending on spawnscript line.

randpal.c:
C:
void main()
{
    int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
    if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
    changeentityproperty(getlocalvar("self"), "map", palette); //APPLY THE PALETTE
}

Example:
Code:
spawn        Shermie-L1
spawnscript data/scripts/randpal.c
coords        -20 174
at            400
 
Nice. If you don't want your script tags to be redundant with the same scripts, you can use spawnscript for spawning entities in levels. I just renamed this spawnscript file into "randpal.c" for avoiding script redundancy. But for spawning specifics, I use script tags without depending on spawnscript line.

randpal.c:
C:
void main()
{
    int palette = (rand()%10); //RANDOM NUMBER FROM 9 TO -9, NOTE THAT 10 MEANS 0 TO 9
    if(palette < 0){palette = palette*(-1);} //CONVERT ALL NEGATIVE NUMBERS TO POSITIVE
    changeentityproperty(getlocalvar("self"), "map", palette); //APPLY THE PALETTE
}

Example:
Code:
spawn        Shermie-L1
spawnscript data/scripts/randpal.c
coords        -20 174
at            400
Thank you. The script has been organized nicely.
 
Back
Top Bottom