Discuss Scratch

Trex1010
Scratcher
8 posts

HELP!!!! CPU programming

I need some help on how to program a character that the computer controls.
Any help?

Thanks, Trex1010
amylaser
Scratcher
500+ posts

HELP!!!! CPU programming

You need to give us more details - there are literally an infinite number of ways you could go about this, depending on what you want your AI to do.

First off, how do you want the CPU-controlled character to act?
Is there an objective it needs to accomplish, in opposition to the human player?
Or does it just perform automated tasks?

It would be great if you could also share the relevant project with us and post a link so we can look at your scripts and give you better answers.

Last edited by amylaser (Oct. 19, 2016 13:29:38)


Art, Animations, and Games!


~click one to check it out~
ghernkhoo
Scratcher
36 posts

HELP!!!! CPU programming

when green flag clicked
if <key [right arrow v] pressed?> then
move (5) steps
end
if <key [left arrow v] pressed?> then
move (-5) steps
end
if <key [up arrow v] pressed?> then
change y by (5)
end
if <key [down arrow v] pressed?> then
change y by (-5 )
end
these are scripts for maze

Last edited by ghernkhoo (Oct. 19, 2016 04:51:18)


This is a signature
Not manually typed
When i post on the forum this shows below what i type
thank you
Roses are red,
Violets are blue.
Omae wa mou
Shindeiru
Trex1010
Scratcher
8 posts

HELP!!!! CPU programming

amylaser wrote:

You need to give us more details - there are literally an infinite number of ways you could go about this, depending on what you want your AI to do.

First off, how do you want the CPU-controlled character to act?
Is there an objective it needs to accomplish, in opposition to the human player?
Or does it just perform automated tasks?

It would be great if you could also share the relevant project with us and post a link so we can look at your scripts and give you better answers.


Yes, sorry I wasn't clear on that. I am making a game where you are battling the CPU on level ground.
The CPU will try to attack the player, and try to dodge the players attacks.

Thanks!
amylaser
Scratcher
500+ posts

HELP!!!! CPU programming

Okay, I'd still urge you to share the project though - we need to know how your current scripts look before we can suggest ways to code the CPU.

List of some more things we'd need to know about:

1) The scripts that determine how the CPU moves. Does it move in bursts of speed? Constant speed? Can it jump, or only move left and right? Can it teleport? Can it fly?

2) The scripts that determine how the CPU attacks. Does it have to be standing near the Player? Can it shoot at the Player from afar? Does it summon falling objects from the sky? Can it aim at the Player, or does it shoot in random directions? By how much does it decrease the Player's health?

3) The scripts that determine how the Player attacks. Does it attack the same way the CPU does? Does it deal damage or knockback?

4) The scripts that determine how the game starts/ends. Does the CPU change its behavior when it reaches a certain level of health? Or what happens to the CPU when either it or the Player “dies”?

So yeah. Please share your project, or show some specific pieces of code you're having trouble with.

Last edited by amylaser (Oct. 22, 2016 01:36:33)


Art, Animations, and Games!


~click one to check it out~
Sports_crazy43
Scratcher
5 posts

HELP!!!! CPU programming

this is my project I want him to run around https://scratch.mit.edu/projects/552370380/
Sports_crazy43
Scratcher
5 posts

HELP!!!! CPU programming

Sports_crazy43 wrote:

this is my project I want him to run around https://scratch.mit.edu/projects/552370380/
constant speed cant do anything elese he needs to score more points than the player

Last edited by Sports_crazy43 (July 30, 2021 14:56:12)

The_Imaginarium
Scratcher
1000+ posts

HELP!!!! CPU programming

Sports_crazy43 wrote:

Sports_crazy43 wrote:

this is my project I want him to run around https://scratch.mit.edu/projects/552370380/
constant speed cant do anything elese he needs to score more points than the player
Please create your own topic instead of posting on someone else's.
orangetheory
Scratcher
500+ posts

HELP!!!! CPU programming

Make a variable called Attacking?

(attacking?)

So the variable changes whenever the player attacks.

Put this in the player that isn't the CPU, or the player that you are supposed to control.

when green flag clicked
forever
if <key [space v] pressed?> then
attacking code here::pen
set [attacking? v] to [y] // y is yes
else
set [attacking? v] to [n] // n is no
end
end

Then in the CPU, put

when green flag clicked
forever
if <touching [character v] ?> then
if <(attacking?) = [y]> then
set [Dodge v] to (pick random (No v) to (Yes v))
end
end
end

Then in same sprite, put

when green flag clicked
forever
if <(Dodge) = [yes]> then
Do Nothing, or put your own code here
else
Getting hurt code here
end
end

Hope this helped!

-Frisbee- -Cricket--Basketball--Forums--Mapping--Coding--Trigonometry master--Mathematics King--Future Prime Minister--Intro-Maker-
I know HTML/CSS, and JavaScript, and with these coding skills I have made some decent projects! Test them out below!
~Archery~Cops + Robbers~
Want an intro, outro, music, effects, or more? Check out the intro shop!

The forum helpers, a place where we help people in the forums
lorick42
Scratcher
19 posts

HELP!!!! CPU programming

Trex1010 wrote:

amylaser wrote:

You need to give us more details - there are literally an infinite number of ways you could go about this, depending on what you want your AI to do.

First off, how do you want the CPU-controlled character to act?
Is there an objective it needs to accomplish, in opposition to the human player?
Or does it just perform automated tasks?

It would be great if you could also share the relevant project with us and post a link so we can look at your scripts and give you better answers.


Yes, sorry I wasn't clear on that. I am making a game where you are battling the CPU on level ground.
The CPU will try to attack the player, and try to dodge the players attacks.

Thanks!
do you wan't a profject like this?: https://scratch.mit.edu/projects/543948839/
orangetheory
Scratcher
500+ posts

HELP!!!! CPU programming

also, this is fairly old and should be closed by now.

-Frisbee- -Cricket--Basketball--Forums--Mapping--Coding--Trigonometry master--Mathematics King--Future Prime Minister--Intro-Maker-
I know HTML/CSS, and JavaScript, and with these coding skills I have made some decent projects! Test them out below!
~Archery~Cops + Robbers~
Want an intro, outro, music, effects, or more? Check out the intro shop!

The forum helpers, a place where we help people in the forums

Powered by DjangoBB