This problem has appeared in other projects, but I found some way around it. Now, not only do I need this to work, but I really want to know how.
So say I have three different outcomes that I want to randomly choose from. Normally I use the choose() function or give each outcome a number and use the random() function to give me a number. The problem comes in when I want one of the particular outcomes to have a better chance of being chosen than another. How do I do this?
- Game Maker Community
- → Viewing Profile: Topics: SHiLLySiT
SHiLLySiT
Member Since 02 Jan 2006Offline Last Active Apr 24 2013 01:46 AM
Community Stats
- Group New Member
- Active Posts 78
- Profile Views 2072
- Member Title GMC Member
- Age 21 years old
- Birthday March 24, 1992
-
Gender
Male
-
Version
GM:Studio
0
none
Topics I've Started
Weighted Chance
18 December 2010 - 05:36 AM
CVS Files
15 December 2010 - 05:42 AM
I've been Google-ing and searching the forums but haven't found anything concrete on reading CSV files. Is it possible to do so in GML? I know I can use arrays to store and manipulate the values within the game, but I'm not sure what to do when it comes to reading/writing to/from external CSV files.
[edit] Oops, I mean CSV files, not CVS.
[edit] Oops, I mean CSV files, not CVS.
Replay system
23 September 2010 - 03:16 AM
What I'm trying achieve is a system where the user can rewind through previous actions. The actual system works-it stores the x,y coordinates ever three seconds in a list with 30 entires. Once it hits 30, it goes back to the first and starts over writing the old entries. (This limits how far the player can rewind and also keeps the game from getting overloaded) Like I said, this system works, so I dont need assistance but if you see/know a better way let me know.
The problem is when I try to draw the path. I originally started trying to draw a circle in code at each point but the circles would start deleting themselves in the middle of the path instead of the end as the rewind system over wrote the old entires. Say these "*" are the circles and this ">" is the player ship: ******* *******>. I would prefer that the circles delete themselves at the END of the path not the MIDDLE.
I decided to simplify the problem but now I cant get the code to delete the instance it pulls from a list, it just creates another marker and stores the values. I used show message() to check inside the "with" statement and it appears the "posdel" varible isn't caring it over to the instance_destroy() because it shows up in the show_message() as a 0.
See the code here:
I know...this method isn't very reasonable, that's why I'm asking for a better way to do this or fix what I have going. Preferably a new way.
edit: Actually i just realized i could create a path for this. I was browsing the manual and found some functions. Don't let this stop suggestions though!
edit2: Okay! I played with the new path functions I found and it made everything so much easier!
Now I have a new problem; after the player has reversed along the path and let go of the key, the code links the last point...oh here to hard to explain:
The recorded path:
http://img251.imageshack.us/content_round.php?page=done&l=img251/1522/screenshot000080.png
After rewind:
]http://img808.images...nshot000081.png
I can't seem to find a way to trim the path from the player's new position to the last point before the rewind. I was trying to combine both the list function and the paths but I haven't turned a result yet.
The problem is when I try to draw the path. I originally started trying to draw a circle in code at each point but the circles would start deleting themselves in the middle of the path instead of the end as the rewind system over wrote the old entires. Say these "*" are the circles and this ">" is the player ship: ******* *******>. I would prefer that the circles delete themselves at the END of the path not the MIDDLE.
I decided to simplify the problem but now I cant get the code to delete the instance it pulls from a list, it just creates another marker and stores the values. I used show message() to check inside the "with" statement and it appears the "posdel" varible isn't caring it over to the instance_destroy() because it shows up in the show_message() as a 0.
See the code here:
if isrewinding=0
{
if time2<alarm2
{time2+=1}
else
{
pos+=1
if pos>max_pos
{pos=0}
//store and draw rewind lines
**This is the part where the code takes a previously stored value from the list and deletes it before creating and storing another value**
posdel=ds_list_find_value(marker,pos)
show_message(posdel)
with (posdel){instance_destroy()} **the instance is not destroyed!**
posnum=instance_create(x,y,obj_marker)
ds_list_insert(marker,pos,posnum)
//store cordinates
ds_list_insert(xrewind,pos,x)
ds_list_insert(yrewind,pos,y)
time2=0
}
}
if keyboard_check(ord("X"))
{
isrewinding=1
if ismoving=0
{
pos-=1
if pos=-1
{pos=max_pos}
if pos=(cur_pos+1)
{show_message("stop")}
xx=ds_list_find_value(xrewind,pos)
yy=ds_list_find_value(yrewind,pos)
move_towards_point(xx,yy,max_vspeed*2)
ismoving=1
}
if distance_to_point(xx,yy)<=5
{ismoving=0}
}
if keyboard_check_pressed(ord("X"))
{cur_pos=pos}
if keyboard_check_released(ord("X"))
{isrewinding=0;ismoving=0}I know...this method isn't very reasonable, that's why I'm asking for a better way to do this or fix what I have going. Preferably a new way.
edit: Actually i just realized i could create a path for this. I was browsing the manual and found some functions. Don't let this stop suggestions though!
edit2: Okay! I played with the new path functions I found and it made everything so much easier!
if isrewinding=0
{
path_add_point(path_rewind,object_index.x,object_index.y,100)
}
if keyboard_check_pressed(ord("X"))
{
isrewinding=1
path_reverse(path_rewind)
path_start(path_rewind,8,0,true)
}
if keyboard_check_released(ord("X"))
{
path_end()
path_reverse(path_rewind)
//path_position=0
isrewinding=0
}This code adds points the the objects path every step of the way (No hit in fps!) and when the player wants to rewind, the path is reversed!Now I have a new problem; after the player has reversed along the path and let go of the key, the code links the last point...oh here to hard to explain:
The recorded path:
http://img251.imageshack.us/content_round.php?page=done&l=img251/1522/screenshot000080.png
After rewind:
]http://img808.images...nshot000081.png
I can't seem to find a way to trim the path from the player's new position to the last point before the rewind. I was trying to combine both the list function and the paths but I haven't turned a result yet.
Inventory
17 August 2010 - 04:31 AM
if keyboard_check(ord("X"))
{
if onitem=1
{
if item.type="consumable"//if item is consumable item
{
{
do
{slot+=1;inventory=ds_list_find_value(global.inventory,slot)}
until (inventory=0)
{
if slot=1
{
item.x=obj_slot1.x
item.y=obj_slot1.y
ds_list_replace(global.inventory,1,1)
}
if slot=2
{
item.x=obj_slot2.x
item.y=obj_slot2.y
ds_list_replace(global.inventory,2,1)
}
if slot=3
{
item.x=obj_slot3.x
item.y=obj_slot3.y
ds_list_replace(global.inventory,3,1)
}
if slot=4
{
item.x=obj_slot4.x
item.y=obj_slot4.y
ds_list_replace(global.inventory,4,1)
}
if slot=5
{
item.x=obj_slot5.x
item.y=obj_slot5.y
ds_list_replace(global.inventory,5,1)
}
if slot=6
{
item.x=obj_slot6.x
item.y=obj_slot6.y
ds_list_replace(global.inventory,6,1)
}
if slot=7
{
item.x=obj_slot7.x
item.y=obj_slot7.y
ds_list_replace(global.inventory,7,1)
}
if slot=8
{
item.x=obj_slot8.x
item.y=obj_slot8.y
ds_list_replace(global.inventory,8,1)
}
if slot=9
{
item.x=obj_slot9.x
item.y=obj_slot9.y
ds_list_replace(global.inventory,9,1)
}
if slot=10
{
item.x=obj_slot10.x
item.y=obj_slot10.y
ds_list_replace(global.inventory,10,1)
}
if slot=11
{exit;}
}
}//end do
item.status="equipped"
slot=0
exit;
}
if item.type="class"//if class item
{
class=item.setclass
with(item){instance_destroy()}
exit;
}
}
}This code is what moves an item from the floor of the game into the player's inventory. It's supposed to check the slots and see which one is empty. The problem is, it keeps placing it in the first slot. This is my first time using a do loop, so I'm pretty sure thats what is causing it.
Please don't suggest an inventory engine, I'd rather write the code my self and understand how it works. Other alternative methods are welcome though. =]
AI for a strategy game
19 July 2010 - 08:22 PM
So I'm not have any problems with game play, in fact, it's already pretty much done. I just recently started on the enemy AI and it's making me pull my hair out. I set up a Google Docs flow chart to help ease my headache with some visual organization: https://docs.google....thkey=CPmj9tQC. (yellow boxes are variables affecting the chance, red boxes are random/chance/choose functions, green and blue are just normal.)
I had a very primitve beginning to this when I was testing the engine with one unit vs firing arrows:
alarm[1]=thinkstep//always set alarm
if ((ceil(irandom(100)))>unitorattack_chance)//decide to create unit or attack
{
//chance_repeat=(ceil(irandom(max_actionpoints/peasant_cost)))
if actionpoints>=peasant_cost//create a peasant
//repeat(chance_repeat)
{
instance_create(x+64,y+88,obj_enemy_peasant)
actionpoints-=2
}
else
{exit}
}
else
{
if (actionpoints>=1)
{
if instance_exists(obj_player_parent)
{
tokill=instance_nearest(x,y,obj_player_parent)
range=distance_to_object(tokill)
dir=point_direction(x,y,(tokill.x),(tokill.y))
dir-=(ceil(irandom_range(15,30)))//angle adjust
arrow=instance_create(x+25,y+45,obj_enemy_arrow)
arrow.dir=dir
with (arrow){motion_set(dir,8)}
actionpoints-=1
}
}
else
{exit}
}
Which worked fine, but now it has gotten very complex; 4 units and 4 abilities plus the enemy needs to judge threat levels. For example, if a player unit is very close to the enemy castle, there needs to be more weight (or more of a chance) on shooting an arrow. Also, the enemy should learn to save when it is low on AP and sometimes decide to save for more powerful units, otherwise after reaching low AP, it will always release an arrow or cheap unit because it doesn't have enough for more.
- Game Maker Community
- → Viewing Profile: Topics: SHiLLySiT
- Privacy Policy
- GMC Rules and Forum Rules ·



Find content