A little Help

For questions about using Classic.

Post » Thu Dec 02, 2010 4:53 am

I have a few questions that i could not find an answer for.

How do i use private variables in objects in python?
When i have something like such

Monster.Hp -= 1
I get a nonetype to int error


Also how do i spawn things using python ive tried a few things but nothing came out.
B
1
G
2
Posts: 3
Reputation: 631

Post » Thu Dec 02, 2010 5:25 pm

Private variables in python are accessed much like with events.
[code:3nd2pf6i]# This gets the value
Sprite.Value('HP')
# This sets the value to 22
Sprite.SetValue('HP', 22)
#This subtracts 1 from the value
Sprite.SubValue('HP', 1)[/code:3nd2pf6i]

Same deal with creating objects:
[code:3nd2pf6i]# This creates a Sprite on layer 1 at 200,300
System.Create('Sprite', 1, 200,300)[/code:3nd2pf6i]
B
79
S
24
G
54
Posts: 4,755
Reputation: 40,773

Post » Thu Dec 02, 2010 11:02 pm

Thanks, I actually figured those things out after while of playing around, i just looked in the menu that appears when u add the dot to an object.
My current dilemma in my ongoing project of trying things out is finding an effective way to make the player unable to move through specific objects (walls).
Maybe you can help me figure this out too.

I have set collision masks on both the wall and object.
Im not using any behavior because i wanted to constrain the player to the layout.
I just made a group of events like such
[code:17juojze]
+Movement
-When Key Up Is Down && Player.Y < 975
-Save Old Y to Private var
-Player.Y += 2
-When Key Up Is Up && Player.Y > 25
-Save Old Y to Private var
-Player.Y -= 2
-When Key Up Is Right && Player.X < 975
-Save Old Y to Private var
-Player.Y += 2
-When Key Up Is Left && Player.X > 25
-Save Old Y to Private var
-Player.X -= 2
When Player is Overlapping Wall
Player.X = OldX
Player.Y = OldX
[/code:17juojze]

But doing that the wall is very rough like i cant go up and down the wall, and occasionally i go into the wall :/. My wall is a 50X 50Y block as a test. :/ Any ideas?
B
1
G
2
Posts: 3
Reputation: 631

Post » Fri Dec 03, 2010 6:54 pm

To prevent going into the wall you could add a "overlapping at offset" condition to check for collisions before motion.
[code:31phvxjq]+ MouseKeyboard: Key Left arrow is down
+ Sprite: [negated] Sprite: overlaps "Solid" : offset (-1,0)
-> Sprite: Set X to.X-1

+ MouseKeyboard: Key Right arrow is down
+ Sprite: [negated] Sprite: overlaps "Solid" : offset (1,0)
-> Sprite: Set X to.X+1

+ MouseKeyboard: Key Up arrow is down
+ Sprite: [negated] Sprite: overlaps "Solid" : offset (0,-1)
-> Sprite: Set Y to.Y-1

+ MouseKeyboard: Key Down arrow is down
+ Sprite: [negated] Sprite: overlaps "Solid" : offset (0,1)
-> Sprite: Set Y to.Y+1
[/code:31phvxjq]
B
79
S
24
G
54
Posts: 4,755
Reputation: 40,773


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests