Kezarus
Endless Game Maker
Hi! I'm having major problems with the statement "with". I ussualy call it like:
Then, after 2 hours of gameplay or more I get erros like:
Those errors happen inside the objects that have no relation with to objPeople, like Game Maker is calling objCamera inside it or objArcaneShot.
The sample code from error 1 is:
The sample code from error 2 is:
If anyone knows something about the with statment and can help me I would appreciate it! =]
Code:
with(objPeople){
if( OwnerName != "" ){
//do stuff
}
}
Those errors happen inside the objects that have no relation with to objPeople, like Game Maker is calling objCamera inside it or objArcaneShot.
The sample code from error 1 is:
Code:
///TownPeopleConceal( Alarm Index )
if( !instance_exists(objWorldMapController) ){
alarm[argument0] = -1;
image_alpha = 1;
}
if( Conceal ){
//IS SOMEONE CLOSE?
var IsSomeoneClose = false;
var MyOwnerName = "";
var MyRace = -1;
var MyType = "";
if( object_index == objTown ){
MyOwnerName = Name;
MyRace = TownRace
}else
if( object_index == objBuilding ){
MyOwnerName = OwnerName;
if( instance_exists(TownOwner) ){
MyRace = TownOwner.TownRace;
}
}else{
MyOwnerName = OwnerName;
if( instance_exists(Owner) ){
MyRace = Owner.TownRace;
}
MyType = Type;
}
with(objPeople){
if( id == other.id ){
//SKIP MYSELF
}else
//************** ERROR HAPPENS HERE
//IT CALLS OBJCAMERA FOR NO REASON
if( OwnerName != MyOwnerName || MyOwnerName == "" || OwnerName == "" ){
if( point_distance(other.x, other.y, x, y) <= 5*TileSize ){
var LocalRace = -1;
if( instance_exists(Owner) && object_index != objPeoplePlayer ){
LocalRace = Owner.TownRace
}
if( object_index == objPeoplePlayer ){
IsSomeoneClose = true;
}else
if( MyType == Type && MyType != "" ){
//DON'T BREAK CONCEAL
}else
if( MyRace == Races.WoodElf && Type == "Beast" ){
//DON'T BREAK CONCEAL
}else
if( LocalRace == Races.WoodElf && MyType == "Beast" ){
//DON'T BREAK CONCEAL
}else{
IsSomeoneClose = true;
}
}
}
}
if( IsSomeoneClose ){
image_alpha += 0.05;
}else{
image_alpha -= 0.05;
}
image_alpha = clamp(image_alpha, 0, 1);
if( image_alpha <= 0 || image_alpha >= 1 ){
alarm[argument0] = 15;
}else{
alarm[argument0] = 1;
}
}else{
alarm[argument0] = -1;
image_alpha = 1;
}
Code:
///RADAR
alarm[3] = 30*2; //RADAR
if( !global.Paused ){
ClosestEnemy = noone;
ClosestEnemyBuilding = noone;
var MyRace = -1;
if( instance_exists(Owner) ){
MyRace = Owner.TownRace;
}
with(objPeople){
if( id != other.id ){ //NOT MYSELF
//NOT FROM MY TOWN OR NO TOWN
//************** ERROR HAPPENS HERE
//IT CALLS OBJATTACK FOR NO REASON
if( OwnerName != other.OwnerName || OwnerName == "" ){
//5 SQUARES RANGE AND VISIBLE
if( point_distance(x,y,other.x,other.y) < 5*TileSize && image_alpha > 0.5 ){
var closest = false; //SEARCH FOR THE CLOSEST
if( other.ClosestEnemy != noone && instance_exists(other.ClosestEnemy) ){
if(
point_distance(x,y,other.x,other.y) <
point_distance(other.ClosestEnemy.x,other.ClosestEnemy.y,other.x,other.y)
){
closest = true;
}
}else{
closest = true;
}
if( closest ){
var MarkEnemy = false;
if( other.EvilFlag == false ){
if( MyRace == Races.WoodElf && Type == "Beast" ){//IF WOOD ELF X BEAST
MarkEnemy = false;
}else
if( EvilFlag == true ){ //EVIL IS HATED BY ALL
MarkEnemy = true;
}else
if( ReputationFunc(other.OwnerName, OwnerName) <= 30 ){ //REP < 30
MarkEnemy = true;
}
}else{
//EVIL HATES ALL BUT SELF
if( EvilFlag == true ){ //IF ME AND OTHER ARE EVIL
if( other.Type != Type ){ //AND DIFF TYPES
MarkEnemy = true;
}
if( OwnerName != other.OwnerName ){
MarkEnemy = true;
}
}else{
MarkEnemy = true;
}
}
if(MarkEnemy){
other.ClosestEnemy = id;
other.alarm[1] = 1;//BEHAVIOR ALARM
other.State = "ENEMY ALERT";
}
}
}
}
}
}
//LONERS DON'T ATTACK BUILDINGS
if( object_is_ancestor(object_index, objPeopleLoner) ){
exit;
}
//NO ENEMIES ON SIGHT
if(ClosestEnemy == noone){
with( objMapDestructible ){
//5 SQUARES RANGE AND VISIBLE
if( point_distance(x,y,other.x,other.y) < 5*TileSize && image_alpha > 0.5 ){
var closest = false; //SEARCH FOR THE CLOSEST
if( other.ClosestEnemyBuilding != noone && instance_exists(other.ClosestEnemyBuilding) ){
if(
point_distance(x,y,other.x,other.y) <
point_distance(other.ClosestEnemyBuilding.x,other.ClosestEnemyBuilding.y,other.x,other.y)
){
closest = true;
}
}else{
closest = true;
}
if( closest ){
var wRepName = "";
if( object_index == objTown ){ wRepName = Name; }
else if( object_is_ancestor(object_index, objTown) ){ wRepName = Name; } //TO GET EVIL CENTERS
else if( object_index == objBuilding ){ wRepName = OwnerName; }
var MarkEnemy = false;
if( EvilFlag ){ //IF DESTRUCTIBLE IS EVIL
if( other.OwnerName != wRepName ){ //NOT FROM THE SAME OWNER
MarkEnemy = true;
}
}else
if( other.EvilFlag ){ //IF TROOP IS EVIL
if( other.OwnerName != wRepName ){ //NOT FROM THE SAME OWNER
MarkEnemy = true;
}
}else
if( ReputationFunc(other.OwnerName, wRepName) <= 30 && closest ){ //REP < 30
MarkEnemy = true;
}
if( MarkEnemy ){
var wTarget = id;
var wMyself = other;
var wTargetIt = true;
with(objBuildingFire){
if( TargetID == wTarget ){ //ALREADY BEING ATTACKED
if( AttackerID != wMyself ){ //AND NOT BY ME
wTargetIt = false;
}
}
}
if( wTargetIt ){
other.ClosestEnemyBuilding = id;
}
}
}
}
}
}
}
Last edited: