/    Sign up×
Community /Pin to ProfileBookmark

Please correct this code (problems with normal and short conditional)

I’ve a game where player and enemies shoot bullets. But I want to make the player bullets different.
In the game there is a main structure for every object(enemies, upgrades, player) called entity.
Then there is another one structure for objects that can move called actor.
then the structure of the bullet.

[CODE]
Entity = function(type,id,x,y,width,height,img){
//….
}
//….
Actor = function(type,id,x,y,width,height,img,hp,atkSpd){
var self = Entity(type,id,x,y,width,height,img);
//….
}
//….
Bullet = function (id,x,y,spdX,spdY,width,height,combatType){
var self = Entity(‘bullet’,id,x,y,width,height,Img.bullet);//Img.bullet is the name of the image of the bullet
//….
}
[/CODE]

I’ve tried this:

[CODE]
Bullet = function (id,x,y,spdX,spdY,width,height,combatType){
var self = Entity(‘bullet’,id,x,y,width,height,(combatType === ‘player’ )? Img.bullet : Img.bullet1 );
//….
}
[/CODE]

Not working… So I’ve tried this

[CODE]
Bullet = function (id,x,y,spdX,spdY,width,height,combatType){
var imagetouse = (combatType === ‘player’ )? Img.bullet : Img.bullet1;
var self = Entity(‘bullet’,id,x,y,width,height, imagetouse );
//….
}
[/CODE]

Not working at all… Then i’ve tried this:

[CODE]
Bullet = function (id,x,y,spdX,spdY,width,height,combatType){
var self;
if ( combatType === ‘player ){
self = Entity(‘bullet’,id,x,y,width,height, Img.bullet );
}
else{
self = Entity(‘bullet’,id,x,y,width,height, Img.bullet1 );
}
//….
[/CODE]

NOT WORKING!!!
why nothing works????????
help me please, and thanks a lot.
excuse me if there is something wrong in the post : this is my first post.
excuse me for the bad english, I’m not from America or UK.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@rccharlesAug 17.2016 — There isn't enough information here for me.

however:

if ( combatType === 'player ){

should be

missing quote.

if ( combatType === 'player' ){
×

Success!

Help @Undefined spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...