Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411512 Posts in 69376 Topics- by 58430 Members - Latest Member: Jesse Webb

April 26, 2024, 08:17:55 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)ds_list_find_index(variable) issues
Pages: [1]
Print
Author Topic: ds_list_find_index(variable) issues  (Read 1445 times)
baconman
Level 10
*****


Design Guru


View Profile WWW
« on: October 06, 2014, 01:16:21 PM »

https://app.box.com/s/y2ovcudfn3s9ldtw2om7 Here's my GMK. Just run that shit and you'll see what's up.

I have a fillRoom1 script that makes a list of room IDs, and then associates them with two values, one that adds obstructions, and the other that adds streams (liquids, spikes), and runs at the Game Start. fillRoom2 is associated with the oRoomCreateCode object, where it's supposed to take these variables, and use them to write the screen associated with the game's ID.

I'm just trying to get it to start, so I can test some enemy AI, and get to coding the doors to change the screen ID correctly. But if even the Start screen won't work...  Cry

The error I'm getting is that "ds_list_find_index(screenlist, screen)" = "screenlist" is an unknown variable (where it's the list ID). *grumble*


Was looking for the grumpy programmer thread to post in, but to no avail.
Logged

ink.inc
Guest
« Reply #1 on: October 06, 2014, 01:32:11 PM »

what object is calling fillroom1 (ie the script that is creating the ds_list)

is it being called at all

all i see is an object called oRoomCreateCode calling fillroom2

ps pls dont have a different object for every direction of an attack, its completely unnecessary
Logged
ink.inc
Guest
« Reply #2 on: October 06, 2014, 01:36:54 PM »



also move all of this into the step event and into code; it's impossible to help you with this stuff otherwise
Logged
baconman
Level 10
*****


Design Guru


View Profile WWW
« Reply #3 on: October 06, 2014, 01:58:50 PM »

Why would that be...? O.o Okay... >.> I did notice a few of the other functions didn't work with D&D code... like that, itself was broken. So I'll take your jist on that.
Logged

ink.inc
Guest
« Reply #4 on: October 06, 2014, 02:11:07 PM »

Why would that be...?

its just a huge pain in the ass to manage/fix

clicking through all of this is enough to make anyone go into conniptions, also it's impossible to search through d&d code
Logged
baconman
Level 10
*****


Design Guru


View Profile WWW
« Reply #5 on: October 06, 2014, 02:19:19 PM »

Done. It's being called in the Game Start event of oRoomCreateCode now, good catch. But still, error sustained. It's not just an error in the scripts themselves?
Logged

baconman
Level 10
*****


Design Guru


View Profile WWW
« Reply #6 on: October 15, 2014, 08:44:32 PM »

This is the code that runs once, at the beginning of each "game."
The idea is that it takes one list (0, 0, 0, 1, 2, 4, 8, 16, 32) and shuffles it. The first 3 resulting in the shuffle are added together to make 3 layers of obstructions, and then the fourth makes a "streampath," which I associate with liquids and spikes and so forth. The idea is that this output makes something like "room number; total obstructions; stream path" in another list, for the "screen coder" to reference.

Really, it should produce one list like (screen id, obstruction) and a second list like (screen id, stream path). These are referenced in the "oRoomCreateCode" object, persistently on the screen. The whole game just takes place on one screen, really.

Code:
//makes two arrays of 225 rooms:
//ds_list(rooms_array) fills the screen with barricades, according to its' calculation...
//ds_list(room_streams) creates the gaps/fluids in the screens according to that one's.

variable_global_set(screenlist, 0)
//variable_global_set(roomfill_id, 0)
//variable_global_set(room_streams, 0)
//variable_global_set(rooms_array, 0)

roomfill_id = ds_list_create()      //make a list for the room-fillers
rooms_array = ds_list_create()      //and one for the list of the totals
room_streams = ds_list_create()     //one for the streams
screenlist = ds_list_create()       //one to identify the screen might be useful too, come to think of it... ^.^' DERP!!

var screens                     //total number of screens
variable_local_set(totalrooms, 0)     //9 sub-grids of 5 x 5 maps?

ds_list_add(roomfill_id, 0)     //populate the list
ds_list_add(roomfill_id, 0)    
ds_list_add(roomfill_id, 0)
ds_list_add(roomfill_id, 1)
ds_list_add(roomfill_id, 2)
ds_list_add(roomfill_id, 4)
ds_list_add(roomfill_id, 8)
ds_list_add(roomfill_id, 16)
ds_list_add(roomfill_id, 32)

var screen                      //just a variable to give each screen a numerical value, like the enum command
var roomfill                    //declare a variable, define it with the first three of the shuffled results
var streampath

for (screens = 255 ; screens = 0; screens -= 1)
{
variable_local_set(screen, screen + 1)
ds_list_add(screenlist, screen)
{
ds_list_shuffle(roomfill_id)    //shuffle the IDs, make them mix up
return roomfill = ds_list_find_index(roomfill_id, argument0) + ds_list_find_index(roomfill_id, argument1) + ds_list_find_index(roomfill_id, argument2)
return streampath = ds_list_find_index(roomfill_id, argument3)
ds_list_add(rooms_array, roomfill)
ds_list_add(room_streams, streampath)
}
}
game_save(world.map)

Then, the second part is a seperate script, meant to deconstruct those variables and populate the screens according to their relative ID. Each power of two creates a particular obstacle layer, which is determined by the "level" associated with the zone. Once I can actually get this much of it running properly, then I'm going to adjust the doorway collision to reference correct zones of 25 screens per group (the screens themselves are 15 tiles wide, 9 tiles tall, not counting exterior walls; and the tiles are 32x32 px). You can see how this stuff lines up in the "room1-action" room.

This part will run every time you cross one "screen" into another, to construct the room associated with it's screen id.

Code:
var barrier                     //declare some barriers according to the level?
var stream
var level

//define the "level"
switch(ds_list_find_index(screenlist, screenid))
    {
    case 0..24:
    variable_local_set(level, 3)    //NW section
    case 25..49:
    variable_local_set(level, 4)    //NC section
    case 50..74:
    variable_local_set(level, 2)    //NE section
    case 75..99:
    variable_local_set(level, 1)    //WC section
    case 100..111:
    variable_local_set(level, 0)    //start section 1
    case 112:
    variable_local_set(level, 5)    //Home Screen, invalid on purpose!! Player begins here.
    case 113..124:
    variable_local_set(level, 0)    //start section
    case 125..149:
    variable_local_set(level, 1)    //EC section
    case 150..174:
    variable_local_set(level, 3)    //SW section
    case 175..199:
    variable_local_set(level, 4)    //SC section
    case 200..224:
    variable_local_set(level, 2)    //SE section
    }
                     //define what the barrier for the level is
//if irandom(750) = 1             //randomly disburse Tinted Rocks?
//then return oTintRock
//else
    switch(level)
{   case 0:
    variable_local_set(barrier, oBush)
    variable_local_set(stream, oWater)
    case 1:
    variable_local_set(barrier, oRock)
    variable_local_set(stream, oHole)
    case 2:
    variable_local_set(barrier, oStatueB)
    variable_local_set(stream, oPoison)
    case 3:
    variable_local_set(barrier, oStatueA)
    variable_local_set(stream, oSpikes)
    case 4:
    variable_local_set(barrier, oSpikeTile)
    variable_local_set(stream, oLava)
    case 5:
    instance_create(240, 240, oStartChest)
    instance_create(368, 240, oStartChest)
    }
//fill and populate the rooms according to the results!

//first, the barriers (since "streams" will overwrite them)

ds_list_find_value(rooms_array, screenid)

if roomfill = 0                   //tag as a special room! Write the special room manually, then set the roomfill/streampath = 0.

then
{
    instance_create(240, 128, oNPC)     //NPC will randomize, and determine special room properties
    instance_create(176, 128, oBonfire)
    instance_create(304, 128, oBonfire)
    }
else
{
    instance_create(112, 176, oEnemySpawn)
    instance_create(112, 368, oEnemySpawn)
    instance_create(304, 272, oEnemySpawn)
    instance_create(304, 272, oItemSpawn)
    instance_create(496, 176, oEnemySpawn)
    instance_create(496, 368, oEnemySpawn)
    }
    
continue

//spawn enemies in the 5 corner/center locations, according to level and openness
//item spawner is in the center, too


//fill the barriers!

if roomfill >= 32

then
    instance_create(272, 160, barrier)
    roomfill -= 32
continue

if roomfill >= 16

then
    instance_create(176, 208, barrier)
    instance_create(144, 240, barrier)
    instance_create(112, 272, barrier)
    instance_create(144, 304, barrier)
    instance_create(176, 336, barrier)
    
    instance_create(336, 208, barrier)
    instance_create(368, 240, barrier)
    instance_create(400, 272, barrier)
    instance_create(368, 304, barrier)
    instance_create(336, 336, barrier)
    
    roomfill -= 16
continue

if roomfill >= 8

then
    instance_create(112, 208, barrier)
    instance_create(112, 336, barrier)
    instance_create(432, 208, barrier)
    instance_create(432, 336, barrier)
    
    roomfill -= 8
continue

if roomfill >= 4

then
    instance_create(176, 304, barrier)
    instance_create(208, 304, barrier)
    instance_create(272, 304, barrier)
    instance_create(304, 304, barrier)
    
    roomfill -= 4
continue

if roomfill >= 2

then
    instance_create(272, 208, barrier)
    instance_create(240, 240, barrier)
    instance_create(304, 240, barrier)
    instance_create(208, 272, oBush)
    instance_create(336, 272, barrier)
    instance_create(240, 304, barrier)
    instance_create(304, 304, barrier)
    instance_create(272, 336, barrier)
    
    roomfill -= 2
continue

if roomfill >= 1

then
    instance_create(176, 272, barrier)
    instance_create(336, 272, barrier)
    
    roomfill -= 1
continue

//barrier setup is complete, now it's time for the stream placement

ds_list_find_value(room_streams, screenid)

if streampath >= 32

then
    instance_create( 80, 208, stream)
    instance_create( 80, 240, stream)
    instance_create( 80, 272, stream)
    instance_create( 80, 304, stream)
    
    instance_create(208, 368, stream)
    instance_create(240, 368, stream)
    instance_create(272, 368, stream)
    instance_create(272, 336, stream)
    instance_create(272, 304, stream)
    instance_create(272, 272, stream)
    instance_create(272, 240, stream)
    instance_create(272, 208, stream)
    instance_create(272, 176, stream)
    instance_create(304, 176, stream)
    instance_create(336, 176, stream)
    
    instance_create(464, 240, stream)
    instance_create(464, 272, stream)
    instance_create(464, 304, stream)
    instance_create(464, 336, stream)

    streampath -= 32
continue

if streampath >= 16

then
    instance_create(144, 208, stream)
    instance_create(144, 240, stream)
    instance_create(144, 272, stream)
    instance_create(144, 304, stream)
    instance_create(176, 304, stream)
    instance_create(204, 304, stream)
    instance_create(240, 304, stream)
    instance_create(240, 336, stream)
    instance_create(240, 368, stream)
    
    instance_create(304, 176, stream)
    instance_create(304, 208, stream)
    instance_create(304, 240, stream)
    instance_create(336, 240, stream)
    instance_create(368, 240, stream)
    instance_create(400, 240, stream)
    instance_create(400, 272, stream)
    instance_create(400, 304, stream)
    instance_create(400, 336, stream)
    
    streampath -= 16
continue

if streampath >= 8

then
    instance_create(144, 176, stream)
    instance_create(144, 208, stream)
    instance_create(172, 176, stream)
    instance_create(172, 208, stream)
    
    instance_create(368, 176, stream)
    instance_create(368, 208, stream)
    instance_create(400, 176, stream)
    instance_create(400, 208, stream)
    
    instance_create(144, 336, stream)
    instance_create(144, 368, stream)
    instance_create(172, 336, stream)
    instance_create(172, 368, stream)

    instance_create(368, 336, stream)
    instance_create(368, 368, stream)
    instance_create(400, 336, stream)
    instance_create(400, 368, stream)
    
    streampath -= 8
continue

if streampath >= 4

then
    instance_create( 48, 144, stream)
    instance_create( 80, 144, stream)
    instance_create(112, 144, stream)
    instance_create(144, 144, stream)
    instance_create( 48, 176, stream)
    instance_create( 80, 176, stream)
    instance_create(112, 177, stream)
    
    instance_create( 48, 336, stream)
    instance_create( 48, 368, stream)
    instance_create( 80, 368, stream)
    instance_create( 48, 400, stream)
    instance_create( 80, 400, stream)
    instance_create(112, 400, stream)
    instance_create(144, 400, stream)
    
    instance_create(400, 144, stream)
    instance_create(432, 144, stream)
    instance_create(464, 144, stream)
    instance_create(496, 144, stream)
    instance_create(464, 176, stream)
    instance_create(496, 176, stream)
    instance_create(496, 176, stream)
    
    instance_create(496, 336, stream)
    instance_create(464, 368, stream)
    instance_create(496, 368, stream)
    instance_create(400, 400, stream)
    instance_create(432, 400, stream)
    instance_create(464, 400, stream)
    instance_create(496, 400, stream)
    
    streampath -= 4
continue

if streampath >= 2

then
    instance_create(208, 208, stream)
    instance_create(176, 208, stream)
    instance_create(144, 208, stream)
    instance_create(144, 240, stream)
    instance_create(144, 240, stream)
    instance_create(144, 304, stream)
    instance_create(144, 336, stream)
    instance_create(176, 336, stream)
    instance_create(208, 336, stream)
    
    instance_create(336, 208, stream)
    instance_create(368, 208, stream)
    instance_create(400, 208, stream)
    instance_create(400, 240, stream)
    instance_create(400, 272, stream)
    instance_create(400, 304, stream)
    instance_create(400, 336, stream)
    instance_create(368, 336, stream)
    instance_create(336, 336, stream)
    
    streampath -= 2
continue

if streampath >= 1

then
    instance_create(208, 272, stream)
    instance_create(240, 272, stream)
    instance_create(272, 272, stream)
    instance_create(304, 272, stream)
    instance_create(336, 272, stream)
    
    streampath -= 1
continue

I still don't know what's making it not work, though. The error I get is an "unknown variable" error, in spite of it being a global variable...

Code:
___________________________________________
ERROR in
action number 2
of Other Event: Room Start
for object oRoomCreateCode:

In script fillRoom2:
Error in code at line 6:
   switch(ds_list_find_index(screenlist, screenid))
                             ^
at position 28: Unknown variable screenlist
« Last Edit: October 15, 2014, 09:19:48 PM by baconman » Logged

mokesmoe
Level 10
*****



View Profile WWW
« Reply #7 on: October 16, 2014, 05:32:13 PM »

The game start event doesn't get called unless it's the first room.

Also don't use global_variable_set().
Global variables seem to only be accessible the way they were set, so you would have to use global_variable_get() whenever you want to retrieve the value.

You can use global.screenlist for both getting/setting, but the best way is probably globalvar.
Use "globalvar screenlist;" (and set it to 0 afterwards if you need to) and then you can just type screenlist to reference the variable.
« Last Edit: October 23, 2014, 04:16:53 AM by mokesmoe » Logged
baconman
Level 10
*****


Design Guru


View Profile WWW
« Reply #8 on: October 16, 2014, 08:41:33 PM »

^ THAT does help a LOT. Although now it's giving me this:

Code:
COMPILATION ERROR in Script: fillRoom1
Error in code at line 13:
   roomfill_id = ds_list_create()   //make a list for the room-fillers
               ^
at position 14: Unexpected symbol in expression.

...out of:

Code:
globalvar screenlist
globalvar screens                     //total number of screens
globalvar totalrooms                //9 sub-grids of 5 x 5 maps?
globalvar screen                      //just a variable to give each screen a numerical value, like the enum command
globalvar roomfill                    //declare a variable, define it with the first three of the shuffled results
globalvar streampath
globalvar roomfill_id

roomfill_id = ds_list_create()   //make a list for the room-fillers
rooms_array = ds_list_create()      //and one for the list of the totals
room_streams = ds_list_create()     //one for the streams
screenlist = ds_list_create()       //one to identify the screen might be useful too, come to think of it... ^.^' DERP!!
Logged

mokesmoe
Level 10
*****



View Profile WWW
« Reply #9 on: October 16, 2014, 10:10:11 PM »

You NEED the semicolon when using var or globalvar.
Otherwise it thinks everything afterwards is a variable declaration. (and you can't use = in variable names hence the error)

also you can do "globalvar screenlist, screens, morevariables;" to save space but it might be less clear to read especially with your comments.

EDIT:
Actually you could probably do this since globalvar persists across lines:

Code:
globalvar screenlist,
screens,                     //total number of screens
totalrooms,                //9 sub-grids of 5 x 5 maps?
screen,                      //just a variable to give each screen a numerical value, like the enum command
roomfill,                    //declare a variable, define it with the first three of the shuffled results
streampath,
roomfill_id;
« Last Edit: October 16, 2014, 10:15:48 PM by mokesmoe » Logged
baconman
Level 10
*****


Design Guru


View Profile WWW
« Reply #10 on: October 20, 2014, 11:10:23 PM »

HUGELY HELPFUL in straightening out my code. I'm still getting that error in fillRoom2 though, that "screenlist" is an undefined variable, even though it's the ID for the list. >.>'
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic